Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Phpspec for symfony 6 #439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function it_sets_code_as_enabled_when_resource_is_new(FormEvent $event, FormInte
$resource->getCode()->willReturn(null);

$form
->add('code', Argument::type('string'), Argument::withEntry('disabled', false))
->add('code', TextType::class, Argument::withEntry('disabled', false))
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -62,7 +63,8 @@ function it_sets_code_as_disabled_when_resource_is_not_new(
$resource->getCode()->willReturn('Code12');

$form
->add('code', Argument::type('string'), Argument::withEntry('disabled', true))
->add('code', TextType::class, Argument::withEntry('disabled', true))
loic425 marked this conversation as resolved.
Show resolved Hide resolved
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -84,6 +86,7 @@ function it_sets_code_as_enabled_when_there_is_no_resource(

$form
->add('code', TextType::class, Argument::withEntry('disabled', false))
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -101,6 +104,7 @@ function it_adds_code_with_specified_type(FormEvent $event, FormInterface $form,

$form
->add('code', FormType::class, Argument::withEntry('disabled', true))
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -116,6 +120,7 @@ function it_adds_code_with_type_text_by_default(FormEvent $event, FormInterface

$form
->add('code', TextType::class, Argument::withEntry('disabled', true))
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -134,6 +139,7 @@ function it_adds_code_with_label_sylius_ui_code_by_default(

$form
->add('code', TextType::class, Argument::withEntry('label', 'sylius.ui.code'))
->willReturn($form)
->shouldBeCalled()
;

Expand All @@ -154,6 +160,7 @@ function it_adds_code_with_specified_type_and_label(

$form
->add('code', FormType::class, Argument::withEntry('label', 'sylius.ui.name'))
->willReturn($form)
->shouldBeCalled()
;

Expand Down