From 6e7b7a89c5eaf9ace3a932d588a8a0c9451daf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 19 Apr 2022 15:33:34 +0200 Subject: [PATCH] Fix Phpspec for Symfony 6 --- .../spec/Controller/ParametersParserSpec.php | 4 +-- .../Controller/ResourceControllerSpec.php | 2 ++ .../Form/Builder/DefaultFormBuilderSpec.php | 31 +++++++++++++++++++ .../AddCodeFormSubscriberSpec.php | 18 +++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/Bundle/spec/Controller/ParametersParserSpec.php b/src/Bundle/spec/Controller/ParametersParserSpec.php index aa678734b..15f02efaf 100644 --- a/src/Bundle/spec/Controller/ParametersParserSpec.php +++ b/src/Bundle/spec/Controller/ParametersParserSpec.php @@ -193,10 +193,10 @@ function it_throws_an_exception_if_array_parameter_is_injected_into_expression() ; } - function it_throws_an_exception_if_object_parameter_is_injected_into_expression(): void + function it_throws_an_exception_if_object_parameter_is_injected_into_expression(\Stringable $object): void { $request = new Request(); - $request->request->set('object', new \stdClass()); + $request->request->set('object', $object->getWrappedObject()); $this ->shouldThrow(\InvalidArgumentException::class) diff --git a/src/Bundle/spec/Controller/ResourceControllerSpec.php b/src/Bundle/spec/Controller/ResourceControllerSpec.php index 33a02a182..a0b24fadf 100644 --- a/src/Bundle/spec/Controller/ResourceControllerSpec.php +++ b/src/Bundle/spec/Controller/ResourceControllerSpec.php @@ -417,6 +417,7 @@ function it_returns_a_html_response_for_creating_new_resource_form( $request->isMethod('POST')->willReturn(false); $form->createView()->willReturn($formView); + $form->handleRequest($request)->willReturn($form); $container->has('templating')->willReturn(false); $container->has('twig')->willReturn(true); @@ -1495,6 +1496,7 @@ function it_uses_response_from_initialize_create_event_if_defined( $request->isMethod('POST')->willReturn(false); $form->createView()->shouldNotBeCalled(); + $form->handleRequest($request)->willReturn($form); $eventDispatcher->dispatchInitializeEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($initializeEvent); $initializeEvent->hasResponse()->willReturn(true); diff --git a/src/Bundle/spec/Doctrine/ORM/Form/Builder/DefaultFormBuilderSpec.php b/src/Bundle/spec/Doctrine/ORM/Form/Builder/DefaultFormBuilderSpec.php index fcbf7beca..2e8e56c30 100644 --- a/src/Bundle/spec/Doctrine/ORM/Form/Builder/DefaultFormBuilderSpec.php +++ b/src/Bundle/spec/Doctrine/ORM/Form/Builder/DefaultFormBuilderSpec.php @@ -67,6 +67,10 @@ function it_excludes_non_natural_identifier_from_the_field_list( $classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT); $classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('id', Argument::cetera())->shouldNotBeCalled(); $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); @@ -93,6 +97,11 @@ function it_does_not_exclude_natural_identifier_from_the_field_list( $classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT); $classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN); + $formBuilder->add('id', null, [])->willReturn($formBuilder); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('id', null, [])->shouldBeCalled(); $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); @@ -117,6 +126,10 @@ function it_uses_metadata_to_create_appropriate_fields( $classMetadataInfo->getTypeOfField('description')->willReturn(Types::TEXT); $classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); $formBuilder->add('enabled', null, [])->shouldBeCalled(); @@ -141,6 +154,11 @@ function it_uses_single_text_widget_for_datetime_field( $classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN); $classMetadataInfo->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('publishedAt', null, ['widget' => 'single_text'])->willReturn($formBuilder); + $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); $formBuilder->add('enabled', null, [])->shouldBeCalled(); @@ -169,6 +187,13 @@ function it_also_creates_fields_for_relations_other_than_one_to_many( $classMetadataInfo->getTypeOfField('enabled')->willReturn(Types::BOOLEAN); $classMetadataInfo->getTypeOfField('publishedAt')->willReturn(Types::DATETIME_MUTABLE); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('publishedAt', null, ['widget' => 'single_text'])->willReturn($formBuilder); + $formBuilder->add('category', null, ['choice_label' => 'id'])->willReturn($formBuilder); + $formBuilder->add('users', Argument::cetera())->willReturn($formBuilder); + $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); $formBuilder->add('enabled', null, [])->shouldBeCalled(); @@ -197,6 +222,12 @@ function it_excludes_common_fields_like_createdAt_and_updatedAt( $classMetadataInfo->getTypeOfField('createdAt')->willReturn(Types::DATETIME_MUTABLE); $classMetadataInfo->getTypeOfField('updatedAt')->willReturn(Types::DATETIME_MUTABLE); + $formBuilder->add('name', null, [])->willReturn($formBuilder); + $formBuilder->add('description', null, [])->willReturn($formBuilder); + $formBuilder->add('enabled', null, [])->willReturn($formBuilder); + $formBuilder->add('createdAt', Argument::cetera())->willReturn($formBuilder); + $formBuilder->add('updatedAt', Argument::cetera())->willReturn($formBuilder); + $formBuilder->add('name', null, [])->shouldBeCalled(); $formBuilder->add('description', null, [])->shouldBeCalled(); $formBuilder->add('enabled', null, [])->shouldBeCalled(); diff --git a/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php b/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php index c70fc4442..d7e0dfa46 100644 --- a/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php +++ b/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php @@ -43,8 +43,10 @@ function it_sets_code_as_enabled_when_resource_is_new(FormEvent $event, FormInte $resource->getCode()->willReturn(null); + $form->add('code', Argument::any(), Argument::withEntry('disabled', false))->willReturn($form); + $form - ->add('code', Argument::type('string'), Argument::withEntry('disabled', false)) + ->add('code', Argument::any(), Argument::withEntry('disabled', false)) ->shouldBeCalled() ; @@ -61,8 +63,10 @@ function it_sets_code_as_disabled_when_resource_is_not_new( $resource->getCode()->willReturn('Code12'); + $form->add('code', Argument::any(), Argument::withEntry('disabled', true))->willReturn($form); + $form - ->add('code', Argument::type('string'), Argument::withEntry('disabled', true)) + ->add('code', Argument::any(), Argument::withEntry('disabled', true)) ->shouldBeCalled() ; @@ -82,6 +86,8 @@ function it_sets_code_as_enabled_when_there_is_no_resource( $event->getData()->willReturn(null); $event->getForm()->willReturn($form); + $form->add('code', TextType::class, Argument::withEntry('disabled', false))->willReturn($form); + $form ->add('code', TextType::class, Argument::withEntry('disabled', false)) ->shouldBeCalled() @@ -99,6 +105,8 @@ function it_adds_code_with_specified_type(FormEvent $event, FormInterface $form, $resource->getCode()->willReturn('Code12'); + $form->add('code', FormType::class, Argument::withEntry('disabled', true))->willReturn($form); + $form ->add('code', FormType::class, Argument::withEntry('disabled', true)) ->shouldBeCalled() @@ -114,6 +122,8 @@ function it_adds_code_with_type_text_by_default(FormEvent $event, FormInterface $resource->getCode()->willReturn('Code12'); + $form->add('code', TextType::class, Argument::withEntry('disabled', true))->willReturn($form); + $form ->add('code', TextType::class, Argument::withEntry('disabled', true)) ->shouldBeCalled() @@ -132,6 +142,8 @@ function it_adds_code_with_label_sylius_ui_code_by_default( $resource->getCode()->willReturn('banana_resource'); + $form->add('code', TextType::class, Argument::withEntry('label', 'sylius.ui.code'))->willReturn($form); + $form ->add('code', TextType::class, Argument::withEntry('label', 'sylius.ui.code')) ->shouldBeCalled() @@ -152,6 +164,8 @@ function it_adds_code_with_specified_type_and_label( $resource->getCode()->willReturn('Code12'); + $form->add('code', FormType::class, Argument::withEntry('label', 'sylius.ui.name'))->willReturn($form); + $form ->add('code', FormType::class, Argument::withEntry('label', 'sylius.ui.name')) ->shouldBeCalled()