Skip to content

Commit

Permalink
Fix Phpspec for Symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Apr 19, 2022
1 parent 43d63f3 commit 6e7b7a8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Bundle/spec/Controller/ParametersParserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Bundle/spec/Controller/ResourceControllerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
;

Expand All @@ -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()
;

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 6e7b7a8

Please sign in to comment.