From 78487b1f62143b9feeaece55ff6cdd7a953733af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 21 Oct 2024 10:29:44 +0200 Subject: [PATCH 1/3] [phpspec-2-phpunit] migration of tests (Symfony) --- .../OperationEventDispatcherSpec.php | 99 ++++--- .../DispatchPostReadEventProviderSpec.php | 86 +++--- .../ExpressionLanguage/ArgumentParserSpec.php | 35 ++- .../RequestVariablesSpec.php | 35 ++- .../ExpressionLanguage/TokenVariablesSpec.php | 79 +++--- .../VariablesCollectionSpec.php | 44 +-- .../Symfony/Form/Factory/FormFactorySpec.php | 90 +++--- .../RepositoryArgumentResolverSpec.php | 103 +++---- .../Request/State/ApiResponderSpec.php | 116 ++++---- .../Symfony/Request/State/ProviderSpec.php | 182 ++++++------ .../Symfony/Request/State/ResponderSpec.php | 125 ++++---- .../Request/State/TwigResponderSpec.php | 145 +++++----- .../Factory/OperationRouteFactorySpec.php | 267 +++++++----------- .../OperationRouteNameFactorySpec.php | 35 ++- .../BulkOperationRoutePathFactorySpec.php | 30 +- ...ollectionOperationRoutePathFactorySpec.php | 36 ++- .../CreateOperationRoutePathFactorySpec.php | 36 ++- .../DeleteOperationRoutePathFactorySpec.php | 48 ++-- .../ShowOperationRoutePathFactorySpec.php | 42 +-- .../UpdateOperationRoutePathFactorySpec.php | 39 +-- .../Symfony/Routing/RedirectHandlerSpec.php | 193 +++++++------ .../ValidationExceptionListenerSpec.php | 97 ++++--- .../Exception/ValidationExceptionSpec.php | 77 +++-- .../Workflow/OperationStateMachineSpec.php | 108 +++---- 24 files changed, 1117 insertions(+), 1030 deletions(-) diff --git a/src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php b/src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php index 1109b6f09..3b3b0023d 100644 --- a/src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php +++ b/src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\EventDispatcher; +namespace Sylius\Resource\Tests\Symfony\EventDispatcher; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Metadata\BulkDelete; use Sylius\Resource\Metadata\Create; @@ -23,110 +23,115 @@ use Sylius\Resource\Symfony\EventDispatcher\OperationEventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -final class OperationEventDispatcherSpec extends ObjectBehavior +final class OperationEventDispatcherTest extends TestCase { - function let(EventDispatcherInterface $eventDispatcher): void + private OperationEventDispatcher $operationEventDispatcher; + + private EventDispatcherInterface $eventDispatcher; + + protected function setUp(): void { - $this->beConstructedWith($eventDispatcher); + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->operationEventDispatcher = new OperationEventDispatcher($this->eventDispatcher); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(OperationEventDispatcher::class); + $this->assertInstanceOf(OperationEventDispatcher::class, $this->operationEventDispatcher); } - function it_dispatches_events( - EventDispatcherInterface $eventDispatcher, - \stdClass $data, - ): void { + public function testItDispatchesEvents(): void + { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $show = (new Show(eventShortName: 'read'))->withResource($resource); - $context = new Context(); + $data = new \stdClass(); - $operationEvent = new OperationEvent($data->getWrappedObject(), [ + $operationEvent = new OperationEvent($data, [ 'operation' => $show, 'context' => $context, ]); - $eventDispatcher->dispatch($operationEvent, 'app.book.read')->shouldBeCalled(); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with($operationEvent, 'app.book.read'); - $this->dispatch($data, $show, $context)->shouldHaveType(OperationEvent::class); + $this->operationEventDispatcher->dispatch($data, $show, $context); } - function it_dispatches_events_for_bulk_operations( - EventDispatcherInterface $eventDispatcher, - \ArrayObject $data, - ): void { + public function testItDispatchesEventsForBulkOperations(): void + { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $bulkDelete = (new BulkDelete(eventShortName: 'delete'))->withResource($resource); - $context = new Context(); + $data = new \ArrayObject(); - $operationEvent = new OperationEvent($data->getWrappedObject(), [ + $operationEvent = new OperationEvent($data, [ 'operation' => $bulkDelete, 'context' => $context, ]); - $eventDispatcher->dispatch($operationEvent, 'app.book.bulk_delete')->shouldBeCalled(); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with($operationEvent, 'app.book.bulk_delete'); - $this->dispatchBulkEvent($data, $bulkDelete, $context)->shouldHaveType(OperationEvent::class); + $this->operationEventDispatcher->dispatchBulkEvent($data, $bulkDelete, $context); } - function it_dispatches_pre_events( - EventDispatcherInterface $eventDispatcher, - \stdClass $data, - ): void { + public function testItDispatchesPreEvents(): void + { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $create = (new Create(eventShortName: 'create'))->withResource($resource); - $context = new Context(); + $data = new \stdClass(); - $operationEvent = new OperationEvent($data->getWrappedObject(), [ + $operationEvent = new OperationEvent($data, [ 'operation' => $create, 'context' => $context, ]); - $eventDispatcher->dispatch($operationEvent, 'app.book.pre_create')->shouldBeCalled(); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with($operationEvent, 'app.book.pre_create'); - $this->dispatchPreEvent($data, $create, $context)->shouldHaveType(OperationEvent::class); + $this->operationEventDispatcher->dispatchPreEvent($data, $create, $context); } - function it_dispatches_post_events( - EventDispatcherInterface $eventDispatcher, - \stdClass $data, - ): void { + public function testItDispatchesPostEvents(): void + { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $create = (new Create(eventShortName: 'create'))->withResource($resource); - $context = new Context(); + $data = new \stdClass(); - $operationEvent = new OperationEvent($data->getWrappedObject(), [ + $operationEvent = new OperationEvent($data, [ 'operation' => $create, 'context' => $context, ]); - $eventDispatcher->dispatch($operationEvent, 'app.book.post_create')->shouldBeCalled(); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with($operationEvent, 'app.book.post_create'); - $this->dispatchPostEvent($data, $create, $context)->shouldHaveType(OperationEvent::class); + $this->operationEventDispatcher->dispatchPostEvent($data, $create, $context); } - function it_dispatches_initialize_events( - EventDispatcherInterface $eventDispatcher, - \stdClass $data, - ): void { + public function testItDispatchesInitializeEvents(): void + { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $create = (new Create(eventShortName: 'create'))->withResource($resource); - $context = new Context(); + $data = new \stdClass(); - $operationEvent = new OperationEvent($data->getWrappedObject(), [ + $operationEvent = new OperationEvent($data, [ 'operation' => $create, 'context' => $context, ]); - $eventDispatcher->dispatch($operationEvent, 'app.book.initialize_create')->shouldBeCalled(); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with($operationEvent, 'app.book.initialize_create'); - $this->dispatchInitializeEvent($data, $create, $context)->shouldHaveType(OperationEvent::class); + $this->operationEventDispatcher->dispatchInitializeEvent($data, $create, $context); } } diff --git a/src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php b/src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php index 2dc4decdc..2641779f5 100644 --- a/src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php +++ b/src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\EventDispatcher\State; +namespace Sylius\Resource\Tests\Symfony\EventDispatcher\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Metadata\Index; @@ -23,69 +23,77 @@ use Sylius\Resource\Symfony\EventDispatcher\OperationEventDispatcherInterface; use Sylius\Resource\Symfony\EventDispatcher\State\DispatchPostReadEventProvider; -final class DispatchPostReadEventProviderSpec extends ObjectBehavior +final class DispatchPostReadEventProviderTest extends TestCase { - function let( - ProviderInterface $provider, - OperationEventDispatcherInterface $operationEventDispatcher, - ): void { - $this->beConstructedWith($provider, $operationEventDispatcher); + private DispatchPostReadEventProvider $dispatchPostReadEventProvider; + + private ProviderInterface $provider; + + private OperationEventDispatcherInterface $operationEventDispatcher; + + protected function setUp(): void + { + $this->provider = $this->createMock(ProviderInterface::class); + $this->operationEventDispatcher = $this->createMock(OperationEventDispatcherInterface::class); + $this->dispatchPostReadEventProvider = new DispatchPostReadEventProvider( + $this->provider, + $this->operationEventDispatcher, + ); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(DispatchPostReadEventProvider::class); + $this->assertInstanceOf(DispatchPostReadEventProvider::class, $this->dispatchPostReadEventProvider); } - function it_dispatches_events_for_index_operation( - ProviderInterface $provider, - OperationEventDispatcherInterface $operationEventDispatcher, - ): void { + public function testItDispatchesEventsForIndexOperation(): void + { $operation = new Index(provider: '\App\Provider'); $context = new Context(); - $operationEvent = new OperationEvent(); - $provider->provide($operation, $context)->shouldBeCalled(); + $this->provider->expects($this->once()) + ->method('provide') + ->with($operation, $context); - $operationEventDispatcher->dispatch(null, $operation, $context)->willReturn($operationEvent)->shouldBeCalled(); - $provider->provide($operation, $context)->shouldBeCalled(); + $this->operationEventDispatcher->expects($this->once()) + ->method('dispatch') + ->with(null, $operation, $context) + ->willReturn($operationEvent); - $operationEventDispatcher->dispatch(null, $operation, $context)->shouldBeCalled(); - - $this->provide($operation, $context); + $this->dispatchPostReadEventProvider->provide($operation, $context); } - function it_dispatches_events_for_show_operation( - ProviderInterface $provider, - OperationEventDispatcherInterface $operationEventDispatcher, - ): void { + public function testItDispatchesEventsForShowOperation(): void + { $operation = new Show(provider: '\App\Provider'); $context = new Context(); - $operationEvent = new OperationEvent(); - $provider->provide($operation, $context)->shouldBeCalled(); + $this->provider->expects($this->once()) + ->method('provide') + ->with($operation, $context); - $operationEventDispatcher->dispatch(null, $operation, $context)->willReturn($operationEvent)->shouldBeCalled(); - $provider->provide($operation, $context)->shouldBeCalled(); + $this->operationEventDispatcher->expects($this->once()) + ->method('dispatch') + ->with(null, $operation, $context) + ->willReturn($operationEvent); - $operationEventDispatcher->dispatch(null, $operation, $context)->shouldBeCalled(); - - $this->provide($operation, $context); + $this->dispatchPostReadEventProvider->provide($operation, $context); } - function it_does_not_dispatch_events_for_create_operation( - ProviderInterface $provider, - OperationEventDispatcherInterface $operationEventDispatcher, - ): void { + public function testItDoesNotDispatchEventsForCreateOperation(): void + { $operation = new Create(provider: '\App\Provider'); $context = new Context(); - $provider->provide($operation, $context)->shouldBeCalled(); + $this->provider->expects($this->once()) + ->method('provide') + ->with($operation, $context); - $operationEventDispatcher->dispatch(null, $operation, $context)->shouldNotBeCalled(); + $this->operationEventDispatcher->expects($this->never()) + ->method('dispatch'); - $this->provide($operation, $context); + $this->dispatchPostReadEventProvider->provide($operation, $context); } } diff --git a/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php b/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php index d74154427..c57295599 100644 --- a/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php +++ b/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php @@ -11,36 +11,45 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\ExpressionLanguage; +namespace Sylius\Resource\Tests\Symfony\ExpressionLanguage; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Symfony\ExpressionLanguage\ArgumentParser; use Sylius\Resource\Symfony\ExpressionLanguage\VariablesCollectionInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -final class ArgumentParserSpec extends ObjectBehavior +final class ArgumentParserTest extends TestCase { - function let(VariablesCollectionInterface $variablesCollection): void + private ArgumentParser $argumentParser; + + private VariablesCollectionInterface $variablesCollection; + + protected function setUp(): void { - $this->beConstructedWith(new ExpressionLanguage(), $variablesCollection); + $this->variablesCollection = $this->createMock(VariablesCollectionInterface::class); + $this->argumentParser = new ArgumentParser(new ExpressionLanguage(), $this->variablesCollection); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(ArgumentParser::class); + $this->assertInstanceOf(ArgumentParser::class, $this->argumentParser); } - function it_parses_expressions(VariablesCollectionInterface $variablesCollection): void + public function testItParsesExpressions(): void { - $variablesCollection->getVariables()->willReturn(['foo' => 'fighters']); + $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); - $this->parseExpression('foo')->shouldReturn('fighters'); + $result = $this->argumentParser->parseExpression('foo'); + + $this->assertSame('fighters', $result); } - function it_merges_variables(VariablesCollectionInterface $variablesCollection): void + public function testItMergesVariables(): void { - $variablesCollection->getVariables()->willReturn(['foo' => 'fighters']); + $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); + + $result = $this->argumentParser->parseExpression('foo', ['foo' => 'bar']); - $this->parseExpression('foo', ['foo' => 'bar'])->shouldReturn('bar'); + $this->assertSame('bar', $result); } } diff --git a/src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php b/src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php index 0adf366c4..2c6e3a5da 100644 --- a/src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php +++ b/src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php @@ -11,33 +11,38 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\ExpressionLanguage; +namespace Sylius\Resource\Tests\Symfony\ExpressionLanguage; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Symfony\ExpressionLanguage\RequestVariables; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -final class RequestVariablesSpec extends ObjectBehavior +final class RequestVariablesTest extends TestCase { - function let(RequestStack $requestStack): void + private RequestVariables $requestVariables; + + private RequestStack $requestStack; + + protected function setUp(): void { - $this->beConstructedWith($requestStack); + $this->requestStack = $this->createMock(RequestStack::class); + $this->requestVariables = new RequestVariables($this->requestStack); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(RequestVariables::class); + $this->assertInstanceOf(RequestVariables::class, $this->requestVariables); } - function it_returns_request_vars( - RequestStack $requestStack, - Request $request, - ): void { - $requestStack->getCurrentRequest()->willReturn($request); + public function testItReturnsRequestVars(): void + { + $request = new Request(); + + $this->requestStack->method('getCurrentRequest')->willReturn($request); + + $result = $this->requestVariables->getVariables(); - $this->getVariables()->shouldReturn([ - 'request' => $request, - ]); + $this->assertSame(['request' => $request], $result); } } diff --git a/src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php b/src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php index 8b8d80beb..c60649c32 100644 --- a/src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php +++ b/src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php @@ -11,77 +11,72 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\ExpressionLanguage; +namespace Sylius\Resource\Tests\Symfony\ExpressionLanguage; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Symfony\ExpressionLanguage\TokenVariables; use Symfony\Component\Security\Core\Authentication\Token\NullToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\User\UserInterface; -final class TokenVariablesSpec extends ObjectBehavior +final class TokenVariablesTest extends TestCase { - function let(TokenStorageInterface $tokenStorage): void + private TokenStorageInterface $tokenStorage; + + private TokenVariables $tokenVariables; + + protected function setUp(): void { - $this->beConstructedWith($tokenStorage); + $this->tokenStorage = $this->createMock(TokenStorageInterface::class); + $this->tokenVariables = new TokenVariables($this->tokenStorage); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(TokenVariables::class); + $this->assertInstanceOf(TokenVariables::class, $this->tokenVariables); } - function it_returns_token_and_user_vars( - TokenStorageInterface $tokenStorage, - TokenInterface $token, - UserInterface $user, - ): void { - $tokenStorage->getToken()->willReturn($token); + public function testItReturnsTokenAndUserVars(): void + { + $token = $this->createMock(TokenInterface::class); + $user = $this->createMock(UserInterface::class); - $token->getUser()->willReturn($user); + $this->tokenStorage->method('getToken')->willReturn($token); + $token->method('getUser')->willReturn($user); - $this->getVariables()->shouldReturn([ + $this->assertSame([ 'token' => $token, 'user' => $user, - ]); + ], $this->tokenVariables->getVariables()); } - function it_returns_a_null_token_if_there_is_no_token_on_storage( - TokenStorageInterface $tokenStorage, - TokenInterface $token, - ): void { - $tokenStorage->getToken()->willReturn(null); - - $token->getUser()->willReturn(null); + public function testItReturnsANullTokenIfThereIsNoTokenOnStorage(): void + { + $this->tokenStorage->method('getToken')->willReturn(null); - $this->getVariables()['token']->shouldHaveType(NullToken::class); + $this->assertInstanceOf(NullToken::class, $this->tokenVariables->getVariables()['token']); } - function it_can_return_null_as_user( - TokenStorageInterface $tokenStorage, - TokenInterface $token, - UserInterface $user, - ): void { - $tokenStorage->getToken()->willReturn($token); + public function testItCanReturnNullAsUser(): void + { + $token = $this->createMock(TokenInterface::class); - $token->getUser()->willReturn(null); + $this->tokenStorage->method('getToken')->willReturn($token); + $token->method('getUser')->willReturn(null); - $this->getVariables()->shouldReturn([ + $this->assertSame([ 'token' => $token, 'user' => null, - ]); + ], $this->tokenVariables->getVariables()); } - function it_throws_an_exception_when_there_is_no_token_storage( - TokenStorageInterface $tokenStorage, - TokenInterface $token, - UserInterface $user, - ): void { - $this->beConstructedWith(null); + public function testItThrowsAnExceptionWhenThereIsNoTokenStorage(): void + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The "symfony/security-bundle" must be installed and configured to use the "token" & "user" attribute. Try running "composer require symfony/security-bundle"'); - $this->shouldThrow(new \LogicException('The "symfony/security-bundle" must be installed and configured to use the "token" & "user" attribute. Try running "composer require symfony/security-bundle"')) - ->during('getVariables') - ; + $tokenVariables = new TokenVariables(null); + $tokenVariables->getVariables(); } } diff --git a/src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php b/src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php index d6ee5c9f2..d67141bdf 100644 --- a/src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php +++ b/src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php @@ -11,37 +11,45 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\ExpressionLanguage; +namespace Sylius\Resource\Tests\Symfony\ExpressionLanguage; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Symfony\ExpressionLanguage\VariablesCollection; use Sylius\Resource\Symfony\ExpressionLanguage\VariablesInterface; -final class VariablesCollectionSpec extends ObjectBehavior +final class VariablesCollectionTest extends TestCase { - function let( - VariablesInterface $firstVariables, - VariablesInterface $secondVariables, - ): void { - $this->beConstructedWith([$firstVariables->getWrappedObject(), $secondVariables->getWrappedObject()]); + private VariablesCollection $variablesCollection; + + protected function setUp(): void + { + $firstVariables = $this->createMock(VariablesInterface::class); + $secondVariables = $this->createMock(VariablesInterface::class); + + $this->variablesCollection = new VariablesCollection([$firstVariables, $secondVariables]); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(VariablesCollection::class); + $this->assertInstanceOf(VariablesCollection::class, $this->variablesCollection); } - function it_merges_variables( - VariablesInterface $firstVariables, - VariablesInterface $secondVariables, - ): void { - $firstVariables->getVariables()->willReturn(['foo' => 'bar', 'user' => '123']); - $secondVariables->getVariables()->willReturn(['foo' => 'fighters', 'value' => 'xyz']); + public function testItMergesVariables(): void + { + $firstVariables = $this->createMock(VariablesInterface::class); + $secondVariables = $this->createMock(VariablesInterface::class); + + $firstVariables->method('getVariables')->willReturn(['foo' => 'bar', 'user' => '123']); + $secondVariables->method('getVariables')->willReturn(['foo' => 'fighters', 'value' => 'xyz']); + + $this->variablesCollection = new VariablesCollection([$firstVariables, $secondVariables]); + + $result = $this->variablesCollection->getVariables(); - $this->getVariables()->shouldReturn([ + $this->assertSame([ 'foo' => 'fighters', 'user' => '123', 'value' => 'xyz', - ]); + ], $result); } } diff --git a/src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php b/src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php index c123994d6..55c31ad4b 100644 --- a/src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php +++ b/src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Form\Factory; +namespace Sylius\Resource\Tests\Symfony\Form\Factory; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Context\Option\RequestOption; use Sylius\Resource\Metadata\Operation; @@ -22,65 +22,67 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; -final class FormFactorySpec extends ObjectBehavior +final class FormFactoryTest extends TestCase { - function let(SymfonyFormFactoryInterface $formFactory): void + private SymfonyFormFactoryInterface $formFactory; + + private FormFactory $formFactoryInstance; + + protected function setUp(): void { - $this->beConstructedWith($formFactory); + $this->formFactory = $this->createMock(SymfonyFormFactoryInterface::class); + $this->formFactoryInstance = new FormFactory($this->formFactory); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(FormFactory::class); + $this->assertInstanceOf(FormFactory::class, $this->formFactoryInstance); } - function it_creates_a_form( - Operation $operation, - SymfonyFormFactoryInterface $formFactory, - FormInterface $form, - ): void { - $operation->getFormType()->willReturn('App\Form\DummyType'); - $operation->getFormOptions()->willReturn(['foo' => 'fighters']); + public function testItCreatesAForm(): void + { + $operation = $this->createMock(Operation::class); + $form = $this->createMock(FormInterface::class); + + $operation->method('getFormType')->willReturn('App\Form\DummyType'); + $operation->method('getFormOptions')->willReturn(['foo' => 'fighters']); - $formFactory->createNamed('', 'App\Form\DummyType', null, ['foo' => 'fighters', 'csrf_protection' => false]) - ->willReturn($form) - ->shouldBeCalled() - ; + $this->formFactory->method('createNamed') + ->with('', 'App\Form\DummyType', null, ['foo' => 'fighters', 'csrf_protection' => false]) + ->willReturn($form); - $this->create($operation, new Context())->shouldReturn($form); + $this->assertSame($form, $this->formFactoryInstance->create($operation, new Context())); } - function it_creates_a_form_form_html_request( - Operation $operation, - SymfonyFormFactoryInterface $formFactory, - FormInterface $form, - Request $request, - ): void { - $operation->getFormType()->willReturn('App\Form\DummyType'); - $operation->getFormOptions()->willReturn(['foo' => 'fighters']); + public function testItCreatesAFormForHtmlRequest(): void + { + $operation = $this->createMock(Operation::class); + $form = $this->createMock(FormInterface::class); + $request = $this->createMock(Request::class); + + $operation->method('getFormType')->willReturn('App\Form\DummyType'); + $operation->method('getFormOptions')->willReturn(['foo' => 'fighters']); - $request->getRequestFormat()->willReturn('html'); + $request->method('getRequestFormat')->willReturn('html'); - $formFactory->create('App\Form\DummyType', null, ['foo' => 'fighters']) - ->willReturn($form) - ->shouldBeCalled() - ; + $this->formFactory->method('create') + ->with('App\Form\DummyType', null, ['foo' => 'fighters']) + ->willReturn($form); - $this->create($operation, new Context(new RequestOption($request->getWrappedObject())))->shouldReturn($form); + $this->assertSame($form, $this->formFactoryInstance->create($operation, new Context(new RequestOption($request->getWrappedObject())))); } - function it_throws_an_exception_when_operation_has_no_form_type( - Operation $operation, - SymfonyFormFactoryInterface $formFactory, - FormInterface $form, - ): void { - $operation->getFormType()->willReturn(null); - $operation->getFormOptions()->willReturn([]); + public function testItThrowsAnExceptionWhenOperationHasNoFormType(): void + { + $operation = $this->createMock(Operation::class); + + $operation->method('getFormType')->willReturn(null); + $operation->method('getFormOptions')->willReturn([]); + $operation->method('getName')->willReturn('app_dummy_create'); - $operation->getName()->willReturn('app_dummy_create'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Operation "app_dummy_create" has no configured form type.'); - $this->shouldThrow(new \RuntimeException('Operation "app_dummy_create" has no configured form type.')) - ->during('create', [$operation, new Context()]) - ; + $this->formFactoryInstance->create($operation, new Context()); } } diff --git a/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php b/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php index 1cc796e1b..f9407899f 100644 --- a/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php +++ b/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Request; +namespace Tests\Sylius\Resource\Symfony\Request; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables; use Sylius\Resource\Reflection\CallableReflection; use Sylius\Resource\Symfony\Request\RepositoryArgumentResolver; @@ -21,101 +21,102 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -final class RepositoryArgumentResolverSpec extends ObjectBehavior +final class RepositoryArgumentResolverTest extends TestCase { - function it_is_initializable(): void + private RepositoryArgumentResolver $repositoryArgumentResolver; + + protected function setUp(): void + { + $this->repositoryArgumentResolver = new RepositoryArgumentResolver(); + } + + public function testIsInitializable(): void { - $this->shouldHaveType(RepositoryArgumentResolver::class); + $this->assertInstanceOf(RepositoryArgumentResolver::class, $this->repositoryArgumentResolver); } - function it_gets_arguments_to_sent_to_the_repository( - Request $request, - ParameterBag $attributes, - ): void { + public function testGetsArgumentsToSendToTheRepository(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $request->attributes = $attributes; $request->query = new InputBag([]); - $request->request = new InputBag(); + $request->request = new InputBag([]); - $attributes->all('_route_params')->willReturn(['id' => 'my_id']); + $attributes->method('all')->with('_route_params')->willReturn(['id' => 'my_id']); $callable = [RepositoryWithCallables::class, 'find']; $reflector = CallableReflection::from($callable); - $this->getArguments($request, $reflector)->shouldReturn([ - 'id' => 'my_id', - ]); + $this->assertSame(['id' => 'my_id'], $this->repositoryArgumentResolver->getArguments($request, $reflector)); } - function it_uses_query_params_when_route_params_are_not_matching( - Request $request, - ParameterBag $attributes, - ): void { + public function testUsesQueryParamsWhenRouteParamsAreNotMatching(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $request->attributes = $attributes; $request->query = new InputBag(['id' => 'my_id']); - $request->request = new InputBag(); + $request->request = new InputBag([]); - $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); + $attributes->method('all')->with('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); $callable = [RepositoryWithCallables::class, 'find']; $reflector = CallableReflection::from($callable); - $this->getArguments($request, $reflector)->shouldReturn([ - 'id' => 'my_id', - ]); + $this->assertSame(['id' => 'my_id'], $this->repositoryArgumentResolver->getArguments($request, $reflector)); } - function it_uses_request_params_when_route_params_are_not_matching( - Request $request, - ParameterBag $attributes, - ): void { + public function testUsesRequestParamsWhenRouteParamsAreNotMatching(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $request->attributes = $attributes; - $request->query = new InputBag(); + $request->query = new InputBag([]); $request->request = new InputBag(['id' => 'my_id']); - $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); + $attributes->method('all')->with('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); $callable = [RepositoryWithCallables::class, 'find']; $reflector = CallableReflection::from($callable); - $this->getArguments($request, $reflector)->shouldReturn([ - 'id' => 'my_id', - ]); + $this->assertSame(['id' => 'my_id'], $this->repositoryArgumentResolver->getArguments($request, $reflector)); } - function it_encapsulates_arguments_when_the_method_has_only_one_required_array_argument( - Request $request, - ParameterBag $attributes, - ): void { + public function testEncapsulatesArgumentsWhenTheMethodHasOnlyOneRequiredArrayArgument(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $request->attributes = $attributes; $request->query = new InputBag([]); - $request->request = new InputBag(); + $request->request = new InputBag([]); - $attributes->all('_route_params')->willReturn(['enabled' => 'true', 'author' => 'author@example.com']); + $attributes->method('all')->with('_route_params')->willReturn(['enabled' => 'true', 'author' => 'author@example.com']); $callable = [RepositoryWithCallables::class, 'findOneBy']; $reflector = CallableReflection::from($callable); - $this->getArguments($request, $reflector)->shouldReturn([ - [ - 'enabled' => 'true', - 'author' => 'author@example.com', - ], - ]); + $this->assertSame([['enabled' => 'true', 'author' => 'author@example.com']], $this->repositoryArgumentResolver->getArguments($request, $reflector)); } - function it_return_array_values_when_method_is_magic( - Request $request, - ParameterBag $attributes, - ): void { + public function testReturnArrayValuesWhenMethodIsMagic(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $request->attributes = $attributes; - $request->query = new InputBag(); + $request->query = new InputBag([]); $request->request = new InputBag(['ids' => ['first_id', 'second_id']]); - $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); + $attributes->method('all')->with('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); $callable = [new RepositoryWithCallables(), '__call']; $reflector = CallableReflection::from($callable); - $this->getArguments($request, $reflector)->shouldReturn([['first_id', 'second_id']]); + $this->assertSame([['first_id', 'second_id']], $this->repositoryArgumentResolver->getArguments($request, $reflector)); } } diff --git a/src/Component/spec/Symfony/Request/State/ApiResponderSpec.php b/src/Component/spec/Symfony/Request/State/ApiResponderSpec.php index 6993a570e..f0dd26248 100644 --- a/src/Component/spec/Symfony/Request/State/ApiResponderSpec.php +++ b/src/Component/spec/Symfony/Request/State/ApiResponderSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Request\State; +namespace Sylius\Resource\Tests\Symfony\Request\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Context\Option\RequestOption; use Sylius\Resource\Metadata\Create; @@ -26,103 +26,109 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -final class ApiResponderSpec extends ObjectBehavior +final class ApiResponderTest extends TestCase { - function let(): void + private ApiResponder $apiResponder; + + protected function setUp(): void { - $this->beConstructedWith(new ApiHeadersInitiator()); + $this->apiResponder = new ApiResponder(new ApiHeadersInitiator()); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(ApiResponder::class); + $this->assertInstanceOf(ApiResponder::class, $this->apiResponder); } - function it_returns_a_response_with_http_created_for_resource_create( - Request $request, - ParameterBag $attributes, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testItReturnsAResponseWithHttpCreatedForResourceCreate(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; - $request->getRequestFormat()->willReturn('json'); - $request->getMimeType('json')->willReturn('application/json'); + $request->method('getRequestFormat')->willReturn('json'); + $request->method('getMimeType')->with('json')->willReturn('application/json'); - $attributes->getBoolean('is_valid', true)->willReturn(true)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(true); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', name: 'book'); $operation = (new Create())->withResource($resource); - $response = $this->respond('serialized_data', $operation, $context); - $response->shouldHaveType(Response::class); - $response->getStatusCode()->shouldReturn(Response::HTTP_CREATED); + $response = $this->apiResponder->respond('serialized_data', $operation, $context); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_CREATED, $response->getStatusCode()); } - function it_returns_a_response_with_http_no_content_for_resource_update( - Request $request, - ParameterBag $attributes, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testItReturnsAResponseWithHttpNoContentForResourceUpdate(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; - $request->getRequestFormat()->willReturn('json'); - $request->getMimeType('json')->willReturn('application/json'); + $request->method('getRequestFormat')->willReturn('json'); + $request->method('getMimeType')->with('json')->willReturn('application/json'); - $attributes->getBoolean('is_valid', true)->willReturn(true)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(true); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', name: 'book'); $operation = (new Update())->withResource($resource); - $response = $this->respond('serialized_data', $operation, $context); - $response->shouldHaveType(Response::class); - $response->getStatusCode()->shouldReturn(Response::HTTP_NO_CONTENT); + $response = $this->apiResponder->respond('serialized_data', $operation, $context); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); } - function it_returns_a_response_with_http_no_content_for_resource_delete( - Request $request, - ParameterBag $attributes, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testItReturnsAResponseWithHttpNoContentForResourceDelete(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; - $request->getRequestFormat()->willReturn('json'); - $request->getMimeType('json')->willReturn('application/json'); + $request->method('getRequestFormat')->willReturn('json'); + $request->method('getMimeType')->with('json')->willReturn('application/json'); - $attributes->getBoolean('is_valid', true)->willReturn(true)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(true); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', name: 'book'); $operation = (new Delete())->withResource($resource); - $response = $this->respond('serialized_data', $operation, $context); - $response->shouldHaveType(Response::class); - $response->getStatusCode()->shouldReturn(Response::HTTP_NO_CONTENT); + $response = $this->apiResponder->respond('serialized_data', $operation, $context); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); } - function it_returns_a_response_with_http_unprocessable_entity_for_invalid_resource( - Request $request, - ParameterBag $attributes, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testItReturnsAResponseWithHttpUnprocessableEntityForInvalidResource(): void + { + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; - $request->getRequestFormat()->willReturn('json'); - $request->getMimeType('json')->willReturn('application/json'); + $request->method('getRequestFormat')->willReturn('json'); + $request->method('getMimeType')->with('json')->willReturn('application/json'); - $attributes->getBoolean('is_valid', true)->willReturn(false)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(false); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', name: 'book'); $operation = (new Create())->withResource($resource); - $response = $this->respond('serialized_data', $operation, $context); - $response->shouldHaveType(Response::class); - $response->getStatusCode()->shouldReturn(Response::HTTP_UNPROCESSABLE_ENTITY); + $response = $this->apiResponder->respond('serialized_data', $operation, $context); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode()); } } diff --git a/src/Component/spec/Symfony/Request/State/ProviderSpec.php b/src/Component/spec/Symfony/Request/State/ProviderSpec.php index 05d3fbb89..8ceac5baf 100644 --- a/src/Component/spec/Symfony/Request/State/ProviderSpec.php +++ b/src/Component/spec/Symfony/Request/State/ProviderSpec.php @@ -11,10 +11,10 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Request\State; +namespace Tests\Sylius\Resource\Symfony\Request\State; use Pagerfanta\Pagerfanta; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Sylius\Component\Resource\Tests\Dummy\RepositoryWithCallables; use Sylius\Resource\Context\Context; @@ -29,147 +29,153 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -final class ProviderSpec extends ObjectBehavior +final class ProviderTest extends TestCase { - function let(ContainerInterface $locator, ArgumentParserInterface $argumentParser): void + private Provider $provider; + + private ContainerInterface $locator; + + private ArgumentParserInterface $argumentParser; + + protected function setUp(): void { - $this->beConstructedWith($locator, new RepositoryArgumentResolver(), $argumentParser); + $this->locator = $this->createMock(ContainerInterface::class); + $this->argumentParser = $this->createMock(ArgumentParserInterface::class); + $this->provider = new Provider($this->locator, new RepositoryArgumentResolver(), $this->argumentParser); } - function it_is_initializable(): void + public function testIsInitializable(): void { - $this->shouldHaveType(Provider::class); + $this->assertInstanceOf(Provider::class, $this->provider); } - function it_calls_repository_as_callable( - Operation $operation, - Request $request, - ): void { - $operation->getRepository()->willReturn([RepositoryWithCallables::class, 'find']); - $operation->getRepositoryArguments()->willReturn(null); + public function testCallsRepositoryAsCallable(): void + { + $operation = $this->createMock(Operation::class); + $request = $this->createMock(Request::class); + + $operation->method('getRepository')->willReturn([RepositoryWithCallables::class, 'find']); + $operation->method('getRepositoryArguments')->willReturn(null); $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id']]); $request->query = new InputBag([]); $request->request = new InputBag(); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldHaveType(\stdClass::class); - $response->id->shouldReturn('my_id'); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertInstanceOf(\stdClass::class, $response); + $this->assertSame('my_id', $response->id); } - function it_calls_repository_as_string( - Operation $operation, - Request $request, - ContainerInterface $locator, - RepositoryInterface $repository, - \stdClass $stdClass, - ): void { - $operation->getRepository()->willReturn('App\Repository'); - $operation->getRepositoryMethod()->willReturn(null); - $operation->getRepositoryArguments()->willReturn(null); + public function testCallsRepositoryAsString(): void + { + $operation = $this->createMock(Operation::class); + $request = $this->createMock(Request::class); + $repository = $this->createMock(RepositoryInterface::class); + $stdClass = new \stdClass(); + + $operation->method('getRepository')->willReturn('App\Repository'); + $operation->method('getRepositoryMethod')->willReturn(null); + $operation->method('getRepositoryArguments')->willReturn(null); $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); $request->request = new InputBag(); - $locator->has('App\Repository')->willReturn(true); - $locator->get('App\Repository')->willReturn($repository); + $this->locator->method('has')->with('App\Repository')->willReturn(true); + $this->locator->method('get')->with('App\Repository')->willReturn($repository); - $repository->findOneBy(['id' => 'my_id'])->willReturn($stdClass); + $repository->method('findOneBy')->with(['id' => 'my_id'])->willReturn($stdClass); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldReturn($stdClass); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertSame($stdClass, $response); } - function it_calls_create_paginator_by_default_on_collection_operations( - Request $request, - ContainerInterface $locator, - RepositoryInterface $repository, - Pagerfanta $pagerfanta, - ): void { + public function testCallsCreatePaginatorByDefaultOnCollectionOperations(): void + { + $request = $this->createMock(Request::class); $operation = new Index(repository: 'App\Repository'); + $repository = $this->createMock(RepositoryInterface::class); + $pagerfanta = $this->createMock(Pagerfanta::class); $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); $request->request = new InputBag(); - $locator->has('App\Repository')->willReturn(true); - $locator->get('App\Repository')->willReturn($repository); + $this->locator->method('has')->with('App\Repository')->willReturn(true); + $this->locator->method('get')->with('App\Repository')->willReturn($repository); - $repository->createPaginator()->willReturn($pagerfanta)->shouldBeCalled(); - $pagerfanta->setCurrentPage(1)->willReturn($pagerfanta)->shouldBeCalled(); + $repository->method('createPaginator')->willReturn($pagerfanta); + $pagerfanta->expects($this->once())->method('setCurrentPage')->with(1)->willReturn($pagerfanta); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldReturn($pagerfanta); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertSame($pagerfanta, $response); } - function it_sets_current_page_from_request_when_data_is_a_paginator( - Request $request, - ContainerInterface $locator, - RepositoryInterface $repository, - Pagerfanta $pagerfanta, - ): void { + public function testSetsCurrentPageFromRequestWhenDataIsAPaginator(): void + { + $request = $this->createMock(Request::class); $operation = new Index(repository: 'App\Repository'); + $repository = $this->createMock(RepositoryInterface::class); + $pagerfanta = $this->createMock(Pagerfanta::class); $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag(['page' => 42]); $request->request = new InputBag(); - $locator->has('App\Repository')->willReturn(true); - $locator->get('App\Repository')->willReturn($repository); + $this->locator->method('has')->with('App\Repository')->willReturn(true); + $this->locator->method('get')->with('App\Repository')->willReturn($repository); - $repository->createPaginator()->willReturn($pagerfanta)->shouldBeCalled(); - $pagerfanta->setCurrentPage(42)->willReturn($pagerfanta)->shouldBeCalled(); + $repository->method('createPaginator')->willReturn($pagerfanta); + $pagerfanta->expects($this->once())->method('setCurrentPage')->with(42)->willReturn($pagerfanta); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldReturn($pagerfanta); - $pagerfanta->getCurrentPage()->willReturn(42); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertSame($pagerfanta, $response); + $pagerfanta->method('getCurrentPage')->willReturn(42); } - function it_calls_repository_as_string_with_specific_repository_method( - Operation $operation, - Request $request, - ContainerInterface $locator, - RepositoryInterface $repository, - \stdClass $stdClass, - ): void { - $operation->getRepository()->willReturn('App\Repository'); - $operation->getRepositoryMethod()->willReturn('find'); - $operation->getRepositoryArguments()->willReturn(null); + public function testCallsRepositoryAsStringWithSpecificRepositoryMethod(): void + { + $operation = $this->createMock(Operation::class); + $request = $this->createMock(Request::class); + $repository = $this->createMock(RepositoryInterface::class); + $stdClass = new \stdClass(); + + $operation->method('getRepository')->willReturn('App\Repository'); + $operation->method('getRepositoryMethod')->willReturn('find'); + $operation->method('getRepositoryArguments')->willReturn(null); $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); $request->request = new InputBag(); - $locator->has('App\Repository')->willReturn(true); - $locator->get('App\Repository')->willReturn($repository); + $this->locator->method('has')->with('App\Repository')->willReturn(true); + $this->locator->method('get')->with('App\Repository')->willReturn($repository); - $repository->find('my_id')->willReturn($stdClass); + $repository->method('find')->with('my_id')->willReturn($stdClass); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldReturn($stdClass); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertSame($stdClass, $response); } - function it_calls_repository_as_string_with_specific_repository_method_an_arguments( - Operation $operation, - Request $request, - ContainerInterface $locator, - RepositoryInterface $repository, - ArgumentParserInterface $argumentParser, - \stdClass $stdClass, - ): void { - $operation->getRepository()->willReturn('App\Repository'); - $operation->getRepositoryMethod()->willReturn('find'); - $operation->getRepositoryArguments()->willReturn(['id' => "request.attributes.get('id')"]); + public function testCallsRepositoryAsStringWithSpecificRepositoryMethodAndArguments(): void + { + $operation = $this->createMock(Operation::class); + $request = $this->createMock(Request::class); + $repository = $this->createMock(RepositoryInterface::class); + $stdClass = new \stdClass(); + + $operation->method('getRepository')->willReturn('App\Repository'); + $operation->method('getRepositoryMethod')->willReturn('find'); + $operation->method('getRepositoryArguments')->willReturn(['id' => "request.attributes.get('id')"]); - $argumentParser->parseExpression("request.attributes.get('id')")->willReturn('my_id'); + $this->argumentParser->method('parseExpression')->with("request.attributes.get('id')")->willReturn('my_id'); - $locator->has('App\Repository')->willReturn(true); - $locator->get('App\Repository')->willReturn($repository); + $this->locator->method('has')->with('App\Repository')->willReturn(true); + $this->locator->method('get')->with('App\Repository')->willReturn($repository); - $repository->find('my_id')->willReturn($stdClass); + $repository->method('find')->with('my_id')->willReturn($stdClass); - $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->shouldReturn($stdClass); + $response = $this->provider->provide($operation, new Context(new RequestOption($request))); + $this->assertSame($stdClass, $response); } } diff --git a/src/Component/spec/Symfony/Request/State/ResponderSpec.php b/src/Component/spec/Symfony/Request/State/ResponderSpec.php index c0cf91ab1..e66b345d9 100644 --- a/src/Component/spec/Symfony/Request/State/ResponderSpec.php +++ b/src/Component/spec/Symfony/Request/State/ResponderSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Request\State; +namespace Tests\Sylius\Resource\Symfony\Request\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Sylius\Resource\Context\Context; use Sylius\Resource\Context\Option\RequestOption; @@ -23,85 +23,92 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -final class ResponderSpec extends ObjectBehavior +final class ResponderTest extends TestCase { - function let(ContainerInterface $locator): void + private Responder $responder; + + private ContainerInterface $locator; + + protected function setUp(): void { - $this->beConstructedWith($locator); + $this->locator = $this->createMock(ContainerInterface::class); + $this->responder = new Responder($this->locator); } - function it_is_initializable(): void + public function testIsInitializable(): void { - $this->shouldHaveType(Responder::class); + $this->assertInstanceOf(Responder::class, $this->responder); } - function it_uses_html_responder_on_html_format( - \stdClass $data, - Request $request, - ContainerInterface $locator, - ResponderInterface $htmlResponder, - HttpOperation $operation, - Response $response, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); - $request->getRequestFormat()->willReturn('html'); + public function testUsesHtmlResponderOnHtmlFormat(): void + { + $data = new \stdClass(); + $request = $this->createMock(Request::class); + $operation = $this->createMock(HttpOperation::class); + $htmlResponder = $this->createMock(ResponderInterface::class); + $response = $this->createMock(Response::class); + $context = new Context(new RequestOption($request)); + + $request->method('getRequestFormat')->willReturn('html'); - $locator->has('sylius.state_responder.html')->willReturn(true); - $locator->get('sylius.state_responder.html')->willReturn($htmlResponder); + $this->locator->method('has')->with('sylius.state_responder.html')->willReturn(true); + $this->locator->method('get')->with('sylius.state_responder.html')->willReturn($htmlResponder); - $htmlResponder->respond($data, $operation, $context)->willReturn($response)->shouldBeCalled(); + $htmlResponder->expects($this->once())->method('respond')->with($data, $operation, $context)->willReturn($response); - $this->respond($data, $operation, $context); + $this->responder->respond($data, $operation, $context); } - function it_uses_api_responder_on_json_format( - \stdClass $data, - Request $request, - ContainerInterface $locator, - ResponderInterface $apiResponder, - HttpOperation $operation, - Response $response, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); - $request->getRequestFormat()->willReturn('json'); + public function testUsesApiResponderOnJsonFormat(): void + { + $data = new \stdClass(); + $request = $this->createMock(Request::class); + $operation = $this->createMock(HttpOperation::class); + $apiResponder = $this->createMock(ResponderInterface::class); + $response = $this->createMock(Response::class); + $context = new Context(new RequestOption($request)); + + $request->method('getRequestFormat')->willReturn('json'); - $locator->has('sylius.state_responder.api')->willReturn(true); - $locator->get('sylius.state_responder.api')->willReturn($apiResponder); + $this->locator->method('has')->with('sylius.state_responder.api')->willReturn(true); + $this->locator->method('get')->with('sylius.state_responder.api')->willReturn($apiResponder); - $apiResponder->respond($data, $operation, $context)->willReturn($response)->shouldBeCalled(); + $apiResponder->expects($this->once())->method('respond')->with($data, $operation, $context)->willReturn($response); - $this->respond($data, $operation, $context); + $this->responder->respond($data, $operation, $context); } - function it_throw_an_exception_when_html_responder_was_not_found( - \stdClass $data, - Request $request, - ContainerInterface $locator, - HttpOperation $operation, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); - $request->getRequestFormat()->willReturn('html'); + public function testThrowExceptionWhenHtmlResponderWasNotFound(): void + { + $data = new \stdClass(); + $request = $this->createMock(Request::class); + $operation = $this->createMock(HttpOperation::class); + $context = new Context(new RequestOption($request)); + + $request->method('getRequestFormat')->willReturn('html'); + + $this->locator->method('has')->with('sylius.state_responder.html')->willReturn(false); - $locator->has('sylius.state_responder.html')->willReturn(false); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Responder "sylius.state_responder.html" was not found but it should.'); - $this->shouldThrow(new \LogicException('Responder "sylius.state_responder.html" was not found but it should.')) - ->during('respond', [$data, $operation, $context]) - ; + $this->responder->respond($data, $operation, $context); } - function it_throw_an_exception_when_json_responder_was_not_found( - \stdClass $data, - Request $request, - ContainerInterface $locator, - HttpOperation $operation, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); - $request->getRequestFormat()->willReturn('json'); + public function testThrowExceptionWhenJsonResponderWasNotFound(): void + { + $data = new \stdClass(); + $request = $this->createMock(Request::class); + $operation = $this->createMock(HttpOperation::class); + $context = new Context(new RequestOption($request)); + + $request->method('getRequestFormat')->willReturn('json'); + + $this->locator->method('has')->with('sylius.state_responder.api')->willReturn(false); - $locator->has('sylius.state_responder.api')->willReturn(false); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Responder "sylius.state_responder.api" was not found but it should.'); - $this->shouldThrow(new \LogicException('Responder "sylius.state_responder.api" was not found but it should.')) - ->during('respond', [$data, $operation, $context]) - ; + $this->responder->respond($data, $operation, $context); } } diff --git a/src/Component/spec/Symfony/Request/State/TwigResponderSpec.php b/src/Component/spec/Symfony/Request/State/TwigResponderSpec.php index ccba96902..decd6666b 100644 --- a/src/Component/spec/Symfony/Request/State/TwigResponderSpec.php +++ b/src/Component/spec/Symfony/Request/State/TwigResponderSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Request\State; +namespace Tests\Sylius\Resource\Symfony\Request\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Context\Option\RequestOption; use Sylius\Resource\Metadata\Create; @@ -28,121 +28,114 @@ use Symfony\Component\HttpFoundation\Request; use Twig\Environment; -final class TwigResponderSpec extends ObjectBehavior +final class TwigResponderTest extends TestCase { - function let( - Environment $twig, - RedirectHandlerInterface $redirectHandler, - ContextFactoryInterface $contextFactory, - ): void { - $this->beConstructedWith($redirectHandler, $contextFactory, $twig); + private TwigResponder $twigResponder; + + private RedirectHandlerInterface $redirectHandler; + + private ContextFactoryInterface $contextFactory; + + private Environment $twig; + + protected function setUp(): void + { + $this->redirectHandler = $this->createMock(RedirectHandlerInterface::class); + $this->contextFactory = $this->createMock(ContextFactoryInterface::class); + $this->twig = $this->createMock(Environment::class); + $this->twigResponder = new TwigResponder($this->redirectHandler, $this->contextFactory, $this->twig); } - function it_is_initializable(): void + public function testIsInitializable(): void { - $this->shouldHaveType(TwigResponder::class); + $this->assertInstanceOf(TwigResponder::class, $this->twigResponder); } - function it_returns_a_response_for_resource_show( - \stdClass $data, - Request $request, - ParameterBag $attributes, - ContextFactoryInterface $contextFactory, - Environment $twig, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testReturnsAResponseForResourceShow(): void + { + $data = new \stdClass(); + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; + $request->method('isMethodSafe')->willReturn(true); - $request->isMethodSafe()->willReturn(true)->shouldBeCalled(); - - $attributes->getBoolean('is_valid', true)->willReturn(false)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(false); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', name: 'book'); $operation = (new Show(template: 'book/show.html.twig'))->withResource($resource); - $contextFactory->create($data, $operation, $context)->willReturn(['book' => $data]); + $this->contextFactory->method('create')->with($data, $operation, $context)->willReturn(['book' => $data]); + $this->twig->method('render')->with('book/show.html.twig', ['book' => $data])->willReturn('result'); - $twig->render('book/show.html.twig', [ - 'book' => $data->getWrappedObject(), - ])->willReturn('result')->shouldBeCalled(); - - $response = $this->respond($data, $operation, $context); - $response->getStatusCode()->shouldReturn(200); + $response = $this->twigResponder->respond($data, $operation, $context); + $this->assertEquals(200, $response->getStatusCode()); } - function it_returns_a_response_for_resource_index( - \ArrayObject $data, - Request $request, - ParameterBag $attributes, - ContextFactoryInterface $contextFactory, - Environment $twig, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testReturnsAResponseForResourceIndex(): void + { + $data = new \ArrayObject(); + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $context = new Context(new RequestOption($request)); $request->attributes = $attributes; + $request->method('isMethodSafe')->willReturn(true); - $request->isMethodSafe()->willReturn(true)->shouldBeCalled(); - - $attributes->getBoolean('is_valid', true)->willReturn(true)->shouldBeCalled(); - $attributes->get('form')->willReturn(null); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(true); + $attributes->method('get')->with('form')->willReturn(null); $resource = new ResourceMetadata(alias: 'app.book', pluralName: 'books'); $operation = (new Index(template: 'book/index.html.twig'))->withResource($resource); - $contextFactory->create($data, $operation, $context)->willReturn(['books' => $data]); - - $twig->render('book/index.html.twig', [ - 'books' => $data->getWrappedObject(), - ])->willReturn('result')->shouldBeCalled(); + $this->contextFactory->method('create')->with($data, $operation, $context)->willReturn(['books' => $data]); + $this->twig->method('render')->with('book/index.html.twig', ['books' => $data])->willReturn('result'); - $this->respond($data, $operation, $context); + $response = $this->twigResponder->respond($data, $operation, $context); + $this->assertNotNull($response); } - function it_redirect_to_route_after_creation( - \ArrayObject $data, - Request $request, - ParameterBag $attributes, - RedirectHandlerInterface $redirectHandler, - RedirectResponse $response, - ): void { + public function testRedirectToRouteAfterCreation(): void + { + $data = new \ArrayObject(); + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $response = $this->createMock(RedirectResponse::class); + $data->offsetSet('id', 'xyz'); $request->attributes = $attributes; - $request->isMethodSafe()->willReturn(false)->shouldBeCalled(); - $attributes->getBoolean('is_valid', true)->willReturn(true)->shouldBeCalled(); + $request->method('isMethodSafe')->willReturn(false); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(true); $operation = new Create(); + $this->redirectHandler->method('redirectToResource')->with($data, $operation, $request)->willReturn($response); - $redirectHandler->redirectToResource($data, $operation, $request)->willReturn($response); - - $this->respond($data, $operation, new Context(new RequestOption($request->getWrappedObject())))->shouldReturn($response); + $result = $this->twigResponder->respond($data, $operation, new Context(new RequestOption($request))); + $this->assertSame($response, $result); } - function it_response_is_unprocessable_when_validation_has_failed( - \ArrayObject $data, - Request $request, - ParameterBag $attributes, - ContextFactoryInterface $contextFactory, - Environment $twig, - ): void { - $context = new Context(new RequestOption($request->getWrappedObject())); + public function testResponseIsUnprocessableWhenValidationHasFailed(): void + { + $data = new \ArrayObject(); + $request = $this->createMock(Request::class); + $attributes = $this->createMock(ParameterBag::class); + $context = new Context(new RequestOption($request)); $data->offsetSet('id', 'xyz'); $request->attributes = $attributes; - $request->isMethodSafe()->willReturn(false)->shouldBeCalled(); - - $attributes->getBoolean('is_valid', true)->willReturn(false)->shouldBeCalled(); + $request->method('isMethodSafe')->willReturn(false); + $attributes->method('getBoolean')->with('is_valid', true)->willReturn(false); $operation = new Create(); - $contextFactory->create($data, $operation, $context)->willReturn(['books' => $data]); - - $twig->render('', ['books' => $data])->willReturn('twig_content'); + $this->contextFactory->method('create')->with($data, $operation, $context)->willReturn(['books' => $data]); + $this->twig->method('render')->willReturn('twig_content'); - $response = $this->respond($data, $operation, new Context(new RequestOption($request->getWrappedObject()))); - $response->getStatusCode()->shouldReturn(422); + $response = $this->twigResponder->respond($data, $operation, new Context(new RequestOption($request))); + $this->assertEquals(422, $response->getStatusCode()); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php index edc46a93f..25157cd2b 100644 --- a/src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php @@ -11,10 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\BulkDelete; use Sylius\Resource\Metadata\BulkUpdate; use Sylius\Resource\Metadata\Create; @@ -28,265 +27,217 @@ use Sylius\Resource\Symfony\Routing\Factory\OperationRouteFactory; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; -final class OperationRouteFactorySpec extends ObjectBehavior +final class OperationRouteFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void + private OperationRoutePathFactoryInterface $routePathFactory; + + private OperationRouteFactory $operationRouteFactory; + + protected function setUp(): void { - $this->beConstructedWith($routePathFactory); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->operationRouteFactory = new OperationRouteFactory($this->routePathFactory); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(OperationRouteFactory::class); + $this->assertInstanceOf(OperationRouteFactory::class, $this->operationRouteFactory); } - function it_generates_create_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesCreateRoutes(): void + { $operation = new Create(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/new')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/new'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/new'); - $route->getMethods()->shouldReturn(['GET', 'POST']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/new', $route->getPath()); + $this->assertSame(['GET', 'POST'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_index_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesIndexRoutes(): void + { $operation = new Index(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - new Index(), - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies'); - $route->getMethods()->shouldReturn(['GET']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies', $route->getPath()); + $this->assertSame(['GET'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_show_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesShowRoutes(): void + { $operation = new Show(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/{id}')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/{id}'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/{id}'); - $route->getMethods()->shouldReturn(['GET']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/{id}', $route->getPath()); + $this->assertSame(['GET'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_update_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesUpdateRoutes(): void + { $operation = new Update(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/{id}/edit')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/{id}/edit'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/{id}/edit'); - $route->getMethods()->shouldReturn(['GET', 'PUT', 'POST']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/{id}/edit', $route->getPath()); + $this->assertSame(['GET', 'PUT', 'POST'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_delete_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesDeleteRoutes(): void + { $operation = new Delete(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/{id}')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/{id}'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/{id}'); - $route->getMethods()->shouldReturn(['DELETE', 'POST']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/{id}', $route->getPath()); + $this->assertSame(['DELETE', 'POST'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_bulk_delete_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesBulkDeleteRoutes(): void + { $operation = new BulkDelete(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/bulk_delete')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/bulk_delete'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/bulk_delete'); - $route->getMethods()->shouldReturn(['DELETE', 'POST']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/bulk_delete', $route->getPath()); + $this->assertSame(['DELETE', 'POST'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_bulk_update_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesBulkUpdateRoutes(): void + { $operation = new BulkUpdate(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('dummies/bulk_update')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('dummies/bulk_update'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/bulk_update'); - $route->getMethods()->shouldReturn(['PUT', 'PATCH']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/bulk_update', $route->getPath()); + $this->assertSame(['PUT', 'PATCH'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_custom_operations_routes( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesCustomOperationsRoutes(): void + { $operation = new HttpOperation(methods: ['PATCH'], path: 'dummies/{id}/custom'); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath(Argument::cetera())->willReturn('')->shouldNotBeCalled(); + $this->routePathFactory->expects($this->never()) + ->method('createRoutePath'); - $route = $this->create( - $metadata, - new ResourceMetadata('app.dummy'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata('app.dummy'), $operation); - $route->getPath()->shouldReturn('/dummies/{id}/custom'); - $route->getMethods()->shouldReturn(['PATCH']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/{id}/custom', $route->getPath()); + $this->assertSame(['PATCH'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', ], - ]); + ], $route->getDefaults()); } - function it_generates_routes_with_sections( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { + public function testItGeneratesRoutesWithSections(): void + { $operation = new Show(); - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('/dummies/{id}')->shouldBeCalled(); + $this->routePathFactory->expects($this->once()) + ->method('createRoutePath') + ->with($operation, 'dummies') + ->willReturn('/dummies/{id}'); - $route = $this->create( - $metadata, - new ResourceMetadata(alias: 'app.dummy', section: 'admin'), - $operation, - ); + $route = $this->operationRouteFactory->create($metadata, new ResourceMetadata(alias: 'app.dummy', section: 'admin'), $operation); - $route->getPath()->shouldReturn('/dummies/{id}'); - $route->getMethods()->shouldReturn(['GET']); - $route->getDefaults()->shouldReturn([ + $this->assertSame('/dummies/{id}', $route->getPath()); + $this->assertSame(['GET'], $route->getMethods()); + $this->assertSame([ '_controller' => 'sylius.main_controller', '_sylius' => [ 'resource' => 'app.dummy', 'section' => 'admin', ], - ]); - } - - function it_generates_routes_with_vars( - OperationRoutePathFactoryInterface $routePathFactory, - ): void { - $operation = new Index(vars: ['subheader' => 'Managing your library']); - - $metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']); - - $routePathFactory->createRoutePath($operation, 'dummies')->willReturn('/dummies')->shouldBeCalled(); - - $route = $this->create( - $metadata, - new ResourceMetadata(alias: 'app.dummy'), - $operation, - ); - - $route->getDefaults()->shouldReturn([ - '_controller' => 'sylius.main_controller', - '_sylius' => [ - 'resource' => 'app.dummy', - 'vars' => ['subheader' => 'Managing your library'], - ], - ]); + ], $route->getDefaults()); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php index 8a8a79028..5f83dfad1 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php @@ -11,42 +11,51 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RouteName; +namespace Tests\Sylius\Resource\Symfony\Routing\Factory\RouteName; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use RuntimeException; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Metadata\ResourceMetadata; use Sylius\Resource\Symfony\Routing\Factory\RouteName\OperationRouteNameFactory; -final class OperationRouteNameFactorySpec extends ObjectBehavior +final class OperationRouteNameFactoryTest extends TestCase { - function it_is_initializable(): void + private OperationRouteNameFactory $operationRouteNameFactory; + + protected function setUp(): void { - $this->shouldHaveType(OperationRouteNameFactory::class); + $this->operationRouteNameFactory = new OperationRouteNameFactory(); } - function it_create_a_route_name(): void + public function testIsInitializable(): void + { + $this->assertInstanceOf(OperationRouteNameFactory::class, $this->operationRouteNameFactory); + } + + public function testCreateRouteName(): void { $resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app'); $operation = (new Create())->withResource($resource); - $this->createRouteName($operation)->shouldReturn('app_book_create'); + $this->assertSame('app_book_create', $this->operationRouteNameFactory->createRouteName($operation)); } - function it_create_a_route_name_with_a_section(): void + public function testCreateRouteNameWithASection(): void { $resource = new ResourceMetadata(alias: 'app.book', section: 'admin', name: 'book', applicationName: 'app'); $operation = (new Create())->withResource($resource); - $this->createRouteName($operation)->shouldReturn('app_admin_book_create'); + $this->assertSame('app_admin_book_create', $this->operationRouteNameFactory->createRouteName($operation)); } - function it_throws_an_exception_when_operation_has_no_resource(): void + public function testThrowsExceptionWhenOperationHasNoResource(): void { $operation = new Create(); - $this->shouldThrow(new \RuntimeException('No resource was found on the operation "create"')) - ->during('createRouteName', [$operation]) - ; + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('No resource was found on the operation "create"'); + + $this->operationRouteNameFactory->createRouteName($operation); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php index 945052116..ef93b7e41 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php @@ -11,37 +11,41 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\BulkDelete; use Sylius\Resource\Metadata\BulkUpdate; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\BulkOperationRoutePathFactory; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; -final class BulkOperationRoutePathFactorySpec extends ObjectBehavior +final class BulkOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void - { - $this->beConstructedWith($routePathFactory); - } + private OperationRoutePathFactoryInterface $routePathFactory; + + private BulkOperationRoutePathFactory $bulkOperationRoutePathFactory; - function it_is_initializable(): void + protected function setUp(): void { - $this->shouldHaveType(BulkOperationRoutePathFactory::class); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->bulkOperationRoutePathFactory = new BulkOperationRoutePathFactory($this->routePathFactory); } - function it_generates_route_path_for_bulk_delete_operations(): void + public function testItGeneratesRoutePathForBulkDeleteOperations(): void { $operation = new BulkDelete(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/bulk_delete'); + $result = $this->bulkOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/bulk_delete', $result); } - function it_generates_route_path_for_bulk_update_operations(): void + public function testItGeneratesRoutePathForBulkUpdateOperations(): void { $operation = new BulkUpdate(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/bulk_update'); + $result = $this->bulkOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/bulk_update', $result); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php index 6aa4db95f..7ed17cac2 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php @@ -11,44 +11,50 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\Api; use Sylius\Resource\Metadata\Index; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\CollectionOperationRoutePathFactory; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; -final class CollectionOperationRoutePathFactorySpec extends ObjectBehavior +final class CollectionOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void - { - $this->beConstructedWith($routePathFactory); - } + private OperationRoutePathFactoryInterface $routePathFactory; + + private CollectionOperationRoutePathFactory $collectionOperationRoutePathFactory; - function it_is_initializable(): void + protected function setUp(): void { - $this->shouldHaveType(CollectionOperationRoutePathFactory::class); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->collectionOperationRoutePathFactory = new CollectionOperationRoutePathFactory($this->routePathFactory); } - function it_generates_route_path_for_index_operations(): void + public function testItGeneratesRoutePathForIndexOperations(): void { $operation = new Index(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies'); + $result = $this->collectionOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies', $result); } - function it_generates_route_path_for_index_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForIndexOperationsWithCustomShortName(): void { $operation = new Index(shortName: 'list'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/list'); + $result = $this->collectionOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/list', $result); } - function it_generates_route_path_for_api_get_collection_operations(): void + public function testItGeneratesRoutePathForApiGetCollectionOperations(): void { $operation = new Api\GetCollection(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies'); + $result = $this->collectionOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies', $result); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php index 1ebfb3b57..d1ed14a69 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php @@ -11,44 +11,50 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\Api; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\CreateOperationRoutePathFactory; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; -final class CreateOperationRoutePathFactorySpec extends ObjectBehavior +final class CreateOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void - { - $this->beConstructedWith($routePathFactory); - } + private OperationRoutePathFactoryInterface $routePathFactory; + + private CreateOperationRoutePathFactory $createOperationRoutePathFactory; - function it_is_initializable(): void + protected function setUp(): void { - $this->shouldHaveType(CreateOperationRoutePathFactory::class); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->createOperationRoutePathFactory = new CreateOperationRoutePathFactory($this->routePathFactory); } - function it_generates_route_path_for_create_operations(): void + public function testItGeneratesRoutePathForCreateOperations(): void { $operation = new Create(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/new'); + $result = $this->createOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/new', $result); } - function it_generates_route_path_for_create_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForCreateOperationsWithCustomShortName(): void { $operation = new Create(shortName: 'register'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/register'); + $result = $this->createOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/register', $result); } - function it_generates_route_path_for_api_post_operations(): void + public function testItGeneratesRoutePathForApiPostOperations(): void { $operation = new Api\Post(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies'); + $result = $this->createOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies', $result); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php index dbbffde1f..913712d89 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php @@ -11,59 +11,69 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\Api; use Sylius\Resource\Metadata\Delete; use Sylius\Resource\Metadata\ResourceMetadata; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\DeleteOperationRoutePathFactory; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; -final class DeleteOperationRoutePathFactorySpec extends ObjectBehavior +final class DeleteOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void - { - $this->beConstructedWith($routePathFactory); - } + private OperationRoutePathFactoryInterface $routePathFactory; - function it_is_initializable(): void + private DeleteOperationRoutePathFactory $deleteOperationRoutePathFactory; + + protected function setUp(): void { - $this->shouldHaveType(DeleteOperationRoutePathFactory::class); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->deleteOperationRoutePathFactory = new DeleteOperationRoutePathFactory($this->routePathFactory); } - function it_generates_route_path_for_delete_operations(): void + public function testItGeneratesRoutePathForDeleteOperations(): void { $operation = new Delete(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/delete'); + $result = $this->deleteOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}/delete', $result); } - function it_generates_route_path_for_delete_operations_with_custom_identifier(): void + public function testItGeneratesRoutePathForDeleteOperationsWithCustomIdentifier(): void { $operation = (new Delete())->withResource(new ResourceMetadata(identifier: 'code')); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{code}/delete'); + $result = $this->deleteOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{code}/delete', $result); } - function it_generates_route_path_for_update_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForUpdateOperationsWithCustomShortName(): void { $operation = new Delete(shortName: 'remove'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/remove'); + $result = $this->deleteOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}/remove', $result); } - function it_generates_route_path_for_api_delete_operations(): void + public function testItGeneratesRoutePathForApiDeleteOperations(): void { $operation = new Api\Delete(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}'); + $result = $this->deleteOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}', $result); } - function it_generates_route_path_for_api_delete_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForApiDeleteOperationsWithCustomShortName(): void { $operation = new Api\Delete(shortName: 'remove'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/remove'); + $result = $this->deleteOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}/remove', $result); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php index 63ff2e0e0..e83fdac02 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php @@ -11,52 +11,60 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\Api; use Sylius\Resource\Metadata\ResourceMetadata; use Sylius\Resource\Metadata\Show; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\ShowOperationRoutePathFactory; -final class ShowOperationRoutePathFactorySpec extends ObjectBehavior +final class ShowOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void - { - $this->beConstructedWith($routePathFactory); - } + private OperationRoutePathFactoryInterface $routePathFactory; - function it_is_initializable(): void + private ShowOperationRoutePathFactory $showOperationRoutePathFactory; + + protected function setUp(): void { - $this->shouldHaveType(ShowOperationRoutePathFactory::class); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->showOperationRoutePathFactory = new ShowOperationRoutePathFactory($this->routePathFactory); } - function it_generates_route_path_for_show_operations(): void + public function testItGeneratesRoutePathForShowOperations(): void { $operation = new Show(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}'); + $result = $this->showOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}', $result); } - function it_generates_route_path_for_delete_operations_with_custom_identifier(): void + public function testItGeneratesRoutePathForShowOperationsWithCustomIdentifier(): void { $operation = (new Show())->withResource(new ResourceMetadata(identifier: 'code')); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{code}'); + $result = $this->showOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{code}', $result); } - function it_generates_route_path_for_show_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForShowOperationsWithCustomShortName(): void { $operation = new Show(shortName: 'details'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/details'); + $result = $this->showOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}/details', $result); } - function it_generates_route_path_for_api_get_operations(): void + public function testItGeneratesRoutePathForApiGetOperations(): void { $operation = new Api\Get(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}'); + $result = $this->showOperationRoutePathFactory->createRoutePath($operation, '/dummies'); + + $this->assertSame('/dummies/{id}', $result); } } diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php b/src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php index 024540268..265129851 100644 --- a/src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php +++ b/src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php @@ -11,59 +11,64 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing\Factory\RoutePath; +namespace Sylius\Tests\Resource\Symfony\Routing\Factory\RoutePath; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\Api; use Sylius\Resource\Metadata\ResourceMetadata; use Sylius\Resource\Metadata\Update; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactoryInterface; use Sylius\Resource\Symfony\Routing\Factory\RoutePath\UpdateOperationRoutePathFactory; -final class UpdateOperationRoutePathFactorySpec extends ObjectBehavior +final class UpdateOperationRoutePathFactoryTest extends TestCase { - function let(OperationRoutePathFactoryInterface $routePathFactory): void + private OperationRoutePathFactoryInterface $routePathFactory; + + private UpdateOperationRoutePathFactory $updateOperationRoutePathFactory; + + protected function setUp(): void { - $this->beConstructedWith($routePathFactory); + $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); + $this->updateOperationRoutePathFactory = new UpdateOperationRoutePathFactory($this->routePathFactory); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(UpdateOperationRoutePathFactory::class); + $this->assertInstanceOf(UpdateOperationRoutePathFactory::class, $this->updateOperationRoutePathFactory); } - function it_generates_route_path_for_update_operations(): void + public function testItGeneratesRoutePathForUpdateOperations(): void { $operation = new Update(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/edit'); + $this->assertSame('/dummies/{id}/edit', $this->updateOperationRoutePathFactory->createRoutePath($operation, '/dummies')); } - function it_generates_route_path_for_update_operations_with_custom_identifier(): void + public function testItGeneratesRoutePathForUpdateOperationsWithCustomIdentifier(): void { $operation = (new Update())->withResource(new ResourceMetadata(identifier: 'code')); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{code}/edit'); + $this->assertSame('/dummies/{code}/edit', $this->updateOperationRoutePathFactory->createRoutePath($operation, '/dummies')); } - function it_generates_route_path_for_update_operations_with_custom_short_name(): void + public function testItGeneratesRoutePathForUpdateOperationsWithCustomShortName(): void { $operation = new Update(shortName: 'edition'); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}/edition'); + $this->assertSame('/dummies/{id}/edition', $this->updateOperationRoutePathFactory->createRoutePath($operation, '/dummies')); } - function it_generates_route_path_for_api_put_operations(): void + public function testItGeneratesRoutePathForApiPutOperations(): void { $operation = new Api\Put(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}'); + $this->assertSame('/dummies/{id}', $this->updateOperationRoutePathFactory->createRoutePath($operation, '/dummies')); } - function it_generates_route_path_for_api_patch_operations(): void + public function testItGeneratesRoutePathForApiPatchOperations(): void { $operation = new Api\Patch(); - $this->createRoutePath($operation, '/dummies')->shouldReturn('/dummies/{id}'); + $this->assertSame('/dummies/{id}', $this->updateOperationRoutePathFactory->createRoutePath($operation, '/dummies')); } } diff --git a/src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php b/src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php index 82f6fff81..57082f03d 100644 --- a/src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php +++ b/src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php @@ -11,10 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Routing; +namespace Sylius\Tests\Resource\Symfony\Routing; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Metadata\BulkUpdate; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Metadata\Delete; @@ -25,166 +24,182 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; -final class RedirectHandlerSpec extends ObjectBehavior +final class RedirectHandlerTest extends TestCase { - function let( - RouterInterface $router, - ArgumentParserInterface $argumentParser, - OperationRouteNameFactoryInterface $operationRouteNameFactory, - ): void { - $this->beConstructedWith( - $router, - $argumentParser, - $operationRouteNameFactory, - ); + private RouterInterface $router; + + private ArgumentParserInterface $argumentParser; + + private OperationRouteNameFactoryInterface $operationRouteNameFactory; + + private RedirectHandler $redirectHandler; + + protected function setUp(): void + { + $this->router = $this->createMock(RouterInterface::class); + $this->argumentParser = $this->createMock(ArgumentParserInterface::class); + $this->operationRouteNameFactory = $this->createMock(OperationRouteNameFactoryInterface::class); + $this->redirectHandler = new RedirectHandler($this->router, $this->argumentParser, $this->operationRouteNameFactory); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(RedirectHandler::class); + $this->assertInstanceOf(RedirectHandler::class, $this->redirectHandler); } - function it_redirects_to_resource_with_id_argument_by_default( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithIdArgumentByDefault(): void + { + $data = new \stdClass(); $data->id = 'xyz'; $operation = new Create(redirectToRoute: 'app_dummy_index'); $resource = new ResourceMetadata(alias: 'app.book'); $operation = $operation->withResource($resource); - $router->generate('app_dummy_index', ['id' => 'xyz'])->willReturn('/dummies')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', ['id' => 'xyz']) + ->willReturn('/dummies'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_with_custom_identifier_argument_by_default( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithCustomIdentifierArgumentByDefault(): void + { + $data = new \stdClass(); $data->code = 'xyz'; $operation = new Create(redirectToRoute: 'app_dummy_index'); $resource = new ResourceMetadata(alias: 'app.ok', identifier: 'code'); $operation = $operation->withResource($resource); - $router->generate('app_dummy_index', ['code' => 'xyz'])->willReturn('/dummies')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', ['code' => 'xyz']) + ->willReturn('/dummies'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_with_id_via_property_access( - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithIdViaPropertyAccess(): void + { $data = new BoardGameResource('uid'); $operation = new Create(redirectToRoute: 'app_board_game_index'); $resource = new ResourceMetadata(alias: 'app.board_game'); $operation = $operation->withResource($resource); - $router->generate('app_board_game_index', ['id' => 'uid'])->willReturn('/board-games')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_board_game_index', ['id' => 'uid']) + ->willReturn('/board-games'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_with_custom_arguments( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithCustomArguments(): void + { + $data = new \stdClass(); $data->code = 'xyz'; $operation = new Create(redirectToRoute: 'app_dummy_index', redirectArguments: ['code' => 'resource.code']); $resource = new ResourceMetadata(alias: 'app.book'); $operation = $operation->withResource($resource); - $router->generate('app_dummy_index', ['code' => 'xyz'])->willReturn('/dummies')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', ['code' => 'xyz']) + ->willReturn('/dummies'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_with_id_via_the_getter( - Request $request, - RouterInterface $router, - ArgumentParserInterface $argumentParser, - ): void { + public function testItRedirectsToResourceWithIdViaTheGetter(): void + { $data = new BoardGameResource('uid'); $operation = new Create(redirectToRoute: 'app_board_game_index', redirectArguments: ['id' => 'resource.id()']); $resource = new ResourceMetadata(alias: 'app.board_game'); $operation = $operation->withResource($resource); - $argumentParser->parseExpression('resource.id()', ['resource' => $data])->willReturn('uid'); + $this->argumentParser->expects($this->once()) + ->method('parseExpression') + ->with('resource.id()', ['resource' => $data]) + ->willReturn('uid'); - $router->generate('app_board_game_index', ['id' => 'uid'])->willReturn('/board-games')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_board_game_index', ['id' => 'uid']) + ->willReturn('/board-games'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_without_arguments_after_delete_operation_by_default( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithoutArgumentsAfterDeleteOperationByDefault(): void + { + $data = new \stdClass(); $data->id = 'xyz'; $operation = new Delete(redirectToRoute: 'app_dummy_index'); $resource = new ResourceMetadata(alias: 'app.book'); $operation = $operation->withResource($resource); - $router->generate('app_dummy_index', [])->willReturn('/dummies')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', []) + ->willReturn('/dummies'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_resource_without_arguments_after_bulk_operation_by_default( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItRedirectsToResourceWithoutArgumentsAfterBulkOperationByDefault(): void + { + $data = new \stdClass(); $data->id = 'xyz'; $operation = new BulkUpdate(redirectToRoute: 'app_dummy_index'); $resource = new ResourceMetadata(alias: 'app.book'); $operation = $operation->withResource($resource); - $router->generate('app_dummy_index', [])->willReturn('/dummies')->shouldBeCalled(); + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', []) + ->willReturn('/dummies'); - $this->redirectToResource($data, $operation, $request); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_redirects_to_route( - \stdClass $data, - RouterInterface $router, - ): void { - $router->generate('app_dummy_index', [])->willReturn('/dummies')->shouldBeCalled(); + public function testItRedirectsToRoute(): void + { + $data = new \stdClass(); + + $this->router->expects($this->once()) + ->method('generate') + ->with('app_dummy_index', []) + ->willReturn('/dummies'); - $this->redirectToRoute($data, 'app_dummy_index'); + $this->redirectHandler->redirectToRoute($data, 'app_dummy_index'); } - function it_throws_an_exception_when_operation_has_no_resource( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItThrowsAnExceptionWhenOperationHasNoResource(): void + { + $data = new \stdClass(); $operation = new Create(redirectToRoute: 'app_dummy_index', name: 'app_dummy_create'); - $router->generate(Argument::cetera())->shouldNotBeCalled(); + $this->router->expects($this->never()) + ->method('generate'); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Operation "app_dummy_create" has no resource, but it should.'); - $this->shouldThrow( - new \RuntimeException('Operation "app_dummy_create" has no resource, but it should.'), - )->during('redirectToResource', [$data, $operation, $request]); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } - function it_throws_an_exception_when_operation_has_no_route_redirection( - \stdClass $data, - Request $request, - RouterInterface $router, - ): void { + public function testItThrowsAnExceptionWhenOperationHasNoRouteRedirection(): void + { + $data = new \stdClass(); $operation = new Create(name: 'app_dummy_create'); - $router->generate(Argument::cetera())->shouldNotBeCalled(); + $this->router->expects($this->never()) + ->method('generate'); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Operation "app_dummy_create" has no redirection route, but it should.'); - $this->shouldThrow( - new \RuntimeException('Operation "app_dummy_create" has no redirection route, but it should.'), - )->during('redirectToResource', [$data, $operation, $request]); + $this->redirectHandler->redirectToResource($data, $operation, new Request()); } } diff --git a/src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php b/src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php index d8c9d2e68..3b5d7a67d 100644 --- a/src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php +++ b/src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php @@ -11,10 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Validator\EventListener; +namespace Tests\Sylius\Resource\Symfony\Validator\EventListener; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Symfony\Validator\EventListener\ValidationExceptionListener; use Sylius\Resource\Symfony\Validator\Exception\ValidationException; use Symfony\Component\HttpFoundation\Request; @@ -25,92 +24,96 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\ConstraintViolationList; -use Webmozart\Assert\Assert; -final class ValidationExceptionListenerSpec extends ObjectBehavior +final class ValidationExceptionListenerTest extends TestCase { - function let(SerializerInterface $serializer): void + private ValidationExceptionListener $listener; + + private SerializerInterface $serializer; + + protected function setUp(): void { - $this->beConstructedWith($serializer); + $this->serializer = $this->createMock(SerializerInterface::class); + $this->listener = new ValidationExceptionListener($this->serializer); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(ValidationExceptionListener::class); + $this->assertInstanceOf(ValidationExceptionListener::class, $this->listener); } - function it_transforms_validation_exception_to_a_response( - KernelInterface $kernel, - Request $request, - SerializerInterface $serializer, - ): void { + public function testItTransformsValidationExceptionToAResponse(): void + { + $kernel = $this->createMock(KernelInterface::class); + $request = $this->createMock(Request::class); $violationList = new ConstraintViolationList(); $exception = new ValidationException($violationList); $event = new ExceptionEvent( - $kernel->getWrappedObject(), - $request->getWrappedObject(), + $kernel, + $request, HttpKernelInterface::MAIN_REQUEST, $exception, ); - $request->getRequestFormat()->willReturn('json'); - $request->getMimeType('json')->willReturn('application/json'); + $request->method('getRequestFormat')->willReturn('json'); + $request->method('getMimeType')->with('json')->willReturn('application/json'); - $serializer->serialize($violationList, 'json')->willReturn('serialized_exception')->shouldBeCalled(); + $this->serializer->method('serialize')->with($violationList, 'json')->willReturn('serialized_exception'); - $this->onKernelException($event); + $this->listener->onKernelException($event); $response = $event->getResponse(); - Assert::isInstanceOf($response, Response::class); - Assert::eq($response->getContent(), 'serialized_exception'); - Assert::eq($response->getStatusCode(), 422); - Assert::eq($response->headers, new ResponseHeaderBag([ + $this->assertInstanceOf(Response::class, $response); + $this->assertEquals('serialized_exception', $response->getContent()); + $this->assertEquals(422, $response->getStatusCode()); + $this->assertEquals(new ResponseHeaderBag([ 'Content-Type' => 'application/json; charset=utf-8', 'X-Content-Type-Options' => 'nosniff', 'X-Frame-Options' => 'deny', - ])); + ]), $response->headers); } - function it_does_nothing_on_other_exceptions( - KernelInterface $kernel, - Request $request, - SerializerInterface $serializer, - \Throwable $exception, - ): void { + public function testItDoesNothingOnOtherExceptions(): void + { + $kernel = $this->createMock(KernelInterface::class); + $request = $this->createMock(Request::class); + $exception = $this->createMock(\Throwable::class); + $event = new ExceptionEvent( - $kernel->getWrappedObject(), - $request->getWrappedObject(), + $kernel, + $request, HttpKernelInterface::MAIN_REQUEST, - $exception->getWrappedObject(), + $exception, ); - $serializer->serialize(Argument::cetera())->shouldNotBeCalled(); + $this->serializer->expects($this->never())->method('serialize'); - $this->onKernelException($event); + $this->listener->onKernelException($event); - Assert::null($event->getResponse()); + $this->assertNull($event->getResponse()); } - function it_throws_an_exception_when_serializer_is_not_available( - KernelInterface $kernel, - Request $request, - ): void { - $this->beConstructedWith(null); + public function testItThrowsAnExceptionWhenSerializerIsNotAvailable(): void + { + $this->listener = new ValidationExceptionListener(null); + $kernel = $this->createMock(KernelInterface::class); + $request = $this->createMock(Request::class); $violationList = new ConstraintViolationList(); $exception = new ValidationException($violationList); $event = new ExceptionEvent( - $kernel->getWrappedObject(), - $request->getWrappedObject(), + $kernel, + $request, HttpKernelInterface::MAIN_REQUEST, $exception, ); - $this->shouldThrow(new \LogicException('The Symfony Serializer is not available. Try running "composer require symfony/serializer".')) - ->during('onKernelException', [$event]) - ; + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The Symfony Serializer is not available. Try running "composer require symfony/serializer".'); + + $this->listener->onKernelException($event); } } diff --git a/src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php b/src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php index 562d7c611..9e5eba026 100644 --- a/src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php +++ b/src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php @@ -11,55 +11,74 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Validator\Exception; +namespace Tests\Sylius\Resource\Symfony\Validator\Exception; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Sylius\Resource\Symfony\Validator\Exception\ValidationException; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationList; -final class ValidationExceptionSpec extends ObjectBehavior +final class ValidationExceptionTest extends TestCase { - function let( - ConstraintViolationInterface $firstViolation, - ConstraintViolationInterface $secondViolation, - ): void { - $this->beConstructedWith(new ConstraintViolationList([ - $firstViolation->getWrappedObject(), - $secondViolation->getWrappedObject(), - ])); + private ValidationException $validationException; + + protected function setUp(): void + { + $firstViolation = $this->createMock(ConstraintViolationInterface::class); + $secondViolation = $this->createMock(ConstraintViolationInterface::class); + + $violationList = new ConstraintViolationList([ + $firstViolation, + $secondViolation, + ]); + + $this->validationException = new ValidationException($violationList); } - function it_transforms_exception_into_a_string( - ConstraintViolationInterface $firstViolation, - ConstraintViolationInterface $secondViolation, - ): void { - $firstViolation->getPropertyPath()->willReturn('name'); - $firstViolation->getMessage()->willReturn('This value should not be blank.'); + public function testItTransformsExceptionIntoAString(): void + { + $firstViolation = $this->createMock(ConstraintViolationInterface::class); + $secondViolation = $this->createMock(ConstraintViolationInterface::class); - $secondViolation->getPropertyPath()->willReturn('email'); - $secondViolation->getMessage()->willReturn('This value should not be blank.'); + $firstViolation->method('getPropertyPath')->willReturn('name'); + $firstViolation->method('getMessage')->willReturn('This value should not be blank.'); - $this->__toString()->shouldReturn("name: This value should not be blank.\nemail: This value should not be blank."); + $secondViolation->method('getPropertyPath')->willReturn('email'); + $secondViolation->method('getMessage')->willReturn('This value should not be blank.'); + + $violationList = new ConstraintViolationList([ + $firstViolation, + $secondViolation, + ]); + + $this->validationException = new ValidationException($violationList); + + $this->assertEquals( + "name: This value should not be blank.\nemail: This value should not be blank.", + $this->validationException->__toString(), + ); } - function it_can_be_constructed_with_a_message(): void + public function testItCanBeConstructedWithAMessage(): void { - $this->beConstructedWith(new ConstraintViolationList([]), 'You should not pass!'); + $this->validationException = new ValidationException(new ConstraintViolationList([]), 'You should not pass!'); - $this->getMessage()->shouldReturn('You should not pass!'); + $this->assertEquals('You should not pass!', $this->validationException->getMessage()); } - function it_can_be_constructed_with_a_code(): void + public function testItCanBeConstructedWithACode(): void { - $this->beConstructedWith(new ConstraintViolationList([]), '', 42); + $this->validationException = new ValidationException(new ConstraintViolationList([]), '', 42); - $this->getCode()->shouldReturn(42); + $this->assertEquals(42, $this->validationException->getCode()); } - function it_can_be_constructed_with_a_previous_exception(\Exception $previous): void + public function testItCanBeConstructedWithAPreviousException(): void { - $this->beConstructedWith(new ConstraintViolationList([]), '', 0, $previous->getWrappedObject()); + $previous = new \Exception(); + + $this->validationException = new ValidationException(new ConstraintViolationList([]), '', 0, $previous); - $this->getPrevious()->shouldReturn($previous); + $this->assertSame($previous, $this->validationException->getPrevious()); } } diff --git a/src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php b/src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php index 0bd6aafeb..2f8b7d07d 100644 --- a/src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php +++ b/src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Symfony\Workflow; +namespace Tests\Sylius\Resource\Symfony\Workflow; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Context\Context; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Metadata\Index; @@ -23,85 +23,91 @@ use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Workflow; -final class OperationStateMachineSpec extends ObjectBehavior +final class OperationStateMachineTest extends TestCase { - function let(Registry $registry): void + private OperationStateMachine $operationStateMachine; + + protected function setUp(): void { - $this->beConstructedWith($registry); + $registry = $this->createMock(Registry::class); + $this->operationStateMachine = new OperationStateMachine($registry); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(OperationStateMachine::class); + $this->assertInstanceOf(OperationStateMachine::class, $this->operationStateMachine); } - function it_returns_if_transition_is_possible( - \stdClass $data, - Registry $registry, - Workflow $workflow, - ): void { + public function testReturnsIfTransitionIsPossible(): void + { + $data = new \stdClass(); $operation = new Create(stateMachineTransition: 'publish'); - $registry->get($data, null)->willReturn($workflow); + $registry = $this->createMock(Registry::class); + $workflow = $this->createMock(Workflow::class); + $registry->method('get')->with($data, null)->willReturn($workflow); + $workflow->method('can')->with($data, 'publish')->willReturn(true); - $workflow->can($data, 'publish')->willReturn(true); + $this->operationStateMachine = new OperationStateMachine($registry); - $this->can($data, $operation, new Context())->shouldReturn(true); + $this->assertTrue($this->operationStateMachine->can($data, $operation, new Context())); } - function it_applies_transition( - \stdClass $data, - Registry $registry, - Workflow $workflow, - Marking $marking, - ): void { + public function testAppliesTransition(): void + { + $data = new \stdClass(); $operation = new Create(stateMachineTransition: 'publish'); - $registry->get($data, null)->willReturn($workflow); + $registry = $this->createMock(Registry::class); + $workflow = $this->createMock(Workflow::class); + $marking = $this->createMock(Marking::class); - $workflow->apply($data, 'publish')->willReturn($marking)->shouldBeCalled(); + $registry->method('get')->with($data, null)->willReturn($workflow); + $workflow->expects($this->once())->method('apply')->with($data, 'publish')->willReturn($marking); - $this->apply($data, $operation, new Context()); + $this->operationStateMachine = new OperationStateMachine($registry); + + $this->operationStateMachine->apply($data, $operation, new Context()); } - function it_throws_an_exception_when_operation_has_no_defined_transition( - \stdClass $data, - Registry $registry, - Workflow $workflow, - Marking $marking, - ): void { + public function testThrowsExceptionWhenOperationHasNoDefinedTransition(): void + { + $data = new \stdClass(); $operation = new Create(name: 'app_dummy_create'); - $registry->get($data, null)->willReturn($workflow); + $registry = $this->createMock(Registry::class); + $registry->method('get')->with($data, null)->willReturn($this->createMock(Workflow::class)); - $this->shouldThrow(new \InvalidArgumentException('No State machine transition was found on operation "app_dummy_create".')) - ->during('can', [$data, $operation, new Context()]) - ; + $this->operationStateMachine = new OperationStateMachine($registry); - $this->shouldThrow(new \InvalidArgumentException('No State machine transition was found on operation "app_dummy_create".')) - ->during('apply', [$data, $operation, new Context()]) - ; + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('No State machine transition was found on operation "app_dummy_create".'); + $this->operationStateMachine->can($data, $operation, new Context()); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('No State machine transition was found on operation "app_dummy_create".'); + $this->operationStateMachine->apply($data, $operation, new Context()); } - function it_throws_an_exception_when_symfony_workflow_is_not_available( - \stdClass $data, - ): void { - $this->beConstructedWith(null); + public function testThrowsExceptionWhenSymfonyWorkflowIsNotAvailable(): void + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('You can not use the "state-machine" if Symfony workflow is not available. Try running "composer require symfony/workflow".'); + $this->operationStateMachine = new OperationStateMachine(null); + $data = new \stdClass(); $operation = new Create(stateMachineTransition: 'publish'); - - $this->shouldThrow( - new \LogicException('You can not use the "state-machine" if Symfony workflow is not available. Try running "composer require symfony/workflow".'), - )->during('can', [$data, $operation, new Context()]); + $this->operationStateMachine->can($data, $operation, new Context()); } - function it_throws_an_exception_when_operation_does_not_implement_a_state_machine( - \stdClass $data, - ): void { + public function testThrowsExceptionWhenOperationDoesNotImplementAStateMachine(): void + { + $data = new \stdClass(); $operation = new Index(); - $this->shouldThrow( - new \LogicException(sprintf('Expected an instance of %s. Got: %s', StateMachineAwareOperationInterface::class, Index::class)), - )->during('can', [$data, $operation, new Context()]); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage(sprintf('Expected an instance of %s. Got: %s', StateMachineAwareOperationInterface::class, Index::class)); + + $this->operationStateMachine->can($data, $operation, new Context()); } } From 823ade9eb465a90eb2f0fd1ff7ba0d7e590cc84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 21 Oct 2024 10:45:55 +0200 Subject: [PATCH 2/3] Move tests --- .../ExpressionLanguage/ArgumentParserSpec.php | 55 ---------------- .../ExpressionLanguage/ArgumentParserTest.php | 63 +++++++++++++++++++ .../OperationEventDispatcherTest.php} | 0 .../DispatchPostReadEventProviderTest.php} | 0 .../ExpressionLanguage/ArgumentParserTest.php | 56 +++++++---------- .../RequestVariablesTest.php} | 0 .../TokenVariablesTest.php} | 0 .../VariablesCollectionTest.php} | 0 .../Symfony/Form/Factory/FormFactoryTest.php} | 0 .../RepositoryArgumentResolverTest.php} | 0 .../Request/State/ApiResponderTest.php} | 0 .../Symfony/Request/State/ProviderTest.php} | 0 .../Symfony/Request/State/ResponderTest.php} | 0 .../Request/State/TwigResponderTest.php} | 0 .../Factory/OperationRouteFactoryTest.php} | 0 .../OperationRouteNameFactoryTest.php} | 0 .../BulkOperationRoutePathFactoryTest.php} | 0 ...llectionOperationRoutePathFactoryTest.php} | 0 .../CreateOperationRoutePathFactoryTest.php} | 0 .../DeleteOperationRoutePathFactoryTest.php} | 0 .../ShowOperationRoutePathFactoryTest.php} | 0 .../UpdateOperationRoutePathFactoryTest.php} | 0 .../Symfony/Routing/RedirectHandlerTest.php} | 0 .../ValidationExceptionListenerSpec.php | 0 .../Exception/ValidationExceptionSpec.php | 0 .../Workflow/OperationStateMachineTest.php} | 0 26 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php create mode 100644 src/Component/tests/Integration/Symfony/ExpressionLanguage/ArgumentParserTest.php rename src/Component/{spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php => tests/Symfony/EventDispatcher/OperationEventDispatcherTest.php} (100%) rename src/Component/{spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php => tests/Symfony/EventDispatcher/State/DispatchPostReadEventProviderTest.php} (100%) rename src/Component/{spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php => tests/Symfony/ExpressionLanguage/RequestVariablesTest.php} (100%) rename src/Component/{spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php => tests/Symfony/ExpressionLanguage/TokenVariablesTest.php} (100%) rename src/Component/{spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php => tests/Symfony/ExpressionLanguage/VariablesCollectionTest.php} (100%) rename src/Component/{spec/Symfony/Form/Factory/FormFactorySpec.php => tests/Symfony/Form/Factory/FormFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Request/RepositoryArgumentResolverSpec.php => tests/Symfony/Request/RepositoryArgumentResolverTest.php} (100%) rename src/Component/{spec/Symfony/Request/State/ApiResponderSpec.php => tests/Symfony/Request/State/ApiResponderTest.php} (100%) rename src/Component/{spec/Symfony/Request/State/ProviderSpec.php => tests/Symfony/Request/State/ProviderTest.php} (100%) rename src/Component/{spec/Symfony/Request/State/ResponderSpec.php => tests/Symfony/Request/State/ResponderTest.php} (100%) rename src/Component/{spec/Symfony/Request/State/TwigResponderSpec.php => tests/Symfony/Request/State/TwigResponderTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php => tests/Symfony/Routing/Factory/OperationRouteFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php => tests/Symfony/Routing/Factory/RouteName/OperationRouteNameFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php => tests/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactoryTest.php} (100%) rename src/Component/{spec/Symfony/Routing/RedirectHandlerSpec.php => tests/Symfony/Routing/RedirectHandlerTest.php} (100%) rename src/Component/{spec => tests}/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php (100%) rename src/Component/{spec => tests}/Symfony/Validator/Exception/ValidationExceptionSpec.php (100%) rename src/Component/{spec/Symfony/Workflow/OperationStateMachineSpec.php => tests/Symfony/Workflow/OperationStateMachineTest.php} (100%) diff --git a/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php b/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php deleted file mode 100644 index c57295599..000000000 --- a/src/Component/spec/Symfony/ExpressionLanguage/ArgumentParserSpec.php +++ /dev/null @@ -1,55 +0,0 @@ -variablesCollection = $this->createMock(VariablesCollectionInterface::class); - $this->argumentParser = new ArgumentParser(new ExpressionLanguage(), $this->variablesCollection); - } - - public function testItIsInitializable(): void - { - $this->assertInstanceOf(ArgumentParser::class, $this->argumentParser); - } - - public function testItParsesExpressions(): void - { - $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); - - $result = $this->argumentParser->parseExpression('foo'); - - $this->assertSame('fighters', $result); - } - - public function testItMergesVariables(): void - { - $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); - - $result = $this->argumentParser->parseExpression('foo', ['foo' => 'bar']); - - $this->assertSame('bar', $result); - } -} diff --git a/src/Component/tests/Integration/Symfony/ExpressionLanguage/ArgumentParserTest.php b/src/Component/tests/Integration/Symfony/ExpressionLanguage/ArgumentParserTest.php new file mode 100644 index 000000000..d62a1ed11 --- /dev/null +++ b/src/Component/tests/Integration/Symfony/ExpressionLanguage/ArgumentParserTest.php @@ -0,0 +1,63 @@ +get('sylius.expression_language.argument_parser.factory'); + + $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); + $this->assertTrue($argumentParser->parseExpression('token.getUser() === null')); + $this->assertTrue($argumentParser->parseExpression('user === null')); + $this->assertTrue($argumentParser->parseExpression('request === null')); + } + + public function testRepositoryArgumentParser(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var ArgumentParserInterface $argumentParser */ + $argumentParser = $container->get('sylius.expression_language.argument_parser.repository'); + + $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); + $this->assertTrue($argumentParser->parseExpression('token.getUser() === null')); + $this->assertTrue($argumentParser->parseExpression('user === null')); + $this->assertTrue($argumentParser->parseExpression('request === null')); + } + + public function testRoutingArgumentParser(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var ArgumentParserInterface $argumentParser */ + $argumentParser = $container->get('sylius.expression_language.argument_parser.routing'); + $this->assertTrue($argumentParser->parseExpression('request === null')); + + $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); + } +} diff --git a/src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php b/src/Component/tests/Symfony/EventDispatcher/OperationEventDispatcherTest.php similarity index 100% rename from src/Component/spec/Symfony/EventDispatcher/OperationEventDispatcherSpec.php rename to src/Component/tests/Symfony/EventDispatcher/OperationEventDispatcherTest.php diff --git a/src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php b/src/Component/tests/Symfony/EventDispatcher/State/DispatchPostReadEventProviderTest.php similarity index 100% rename from src/Component/spec/Symfony/EventDispatcher/State/DispatchPostReadEventProviderSpec.php rename to src/Component/tests/Symfony/EventDispatcher/State/DispatchPostReadEventProviderTest.php diff --git a/src/Component/tests/Symfony/ExpressionLanguage/ArgumentParserTest.php b/src/Component/tests/Symfony/ExpressionLanguage/ArgumentParserTest.php index d62a1ed11..c57295599 100644 --- a/src/Component/tests/Symfony/ExpressionLanguage/ArgumentParserTest.php +++ b/src/Component/tests/Symfony/ExpressionLanguage/ArgumentParserTest.php @@ -11,53 +11,45 @@ declare(strict_types=1); -namespace Sylius\Component\Resource\tests\Symfony\ExpressionLanguage; +namespace Sylius\Resource\Tests\Symfony\ExpressionLanguage; -use Sylius\Resource\Symfony\ExpressionLanguage\ArgumentParserInterface; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use PHPUnit\Framework\TestCase; +use Sylius\Resource\Symfony\ExpressionLanguage\ArgumentParser; +use Sylius\Resource\Symfony\ExpressionLanguage\VariablesCollectionInterface; +use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -final class ArgumentParserTest extends KernelTestCase +final class ArgumentParserTest extends TestCase { - public function testResourceFactoryArgumentParser(): void - { - self::bootKernel(); - - $container = static::getContainer(); + private ArgumentParser $argumentParser; - /** @var ArgumentParserInterface $argumentParser */ - $argumentParser = $container->get('sylius.expression_language.argument_parser.factory'); + private VariablesCollectionInterface $variablesCollection; - $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); - $this->assertTrue($argumentParser->parseExpression('token.getUser() === null')); - $this->assertTrue($argumentParser->parseExpression('user === null')); - $this->assertTrue($argumentParser->parseExpression('request === null')); + protected function setUp(): void + { + $this->variablesCollection = $this->createMock(VariablesCollectionInterface::class); + $this->argumentParser = new ArgumentParser(new ExpressionLanguage(), $this->variablesCollection); } - public function testRepositoryArgumentParser(): void + public function testItIsInitializable(): void { - self::bootKernel(); + $this->assertInstanceOf(ArgumentParser::class, $this->argumentParser); + } - $container = static::getContainer(); + public function testItParsesExpressions(): void + { + $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); - /** @var ArgumentParserInterface $argumentParser */ - $argumentParser = $container->get('sylius.expression_language.argument_parser.repository'); + $result = $this->argumentParser->parseExpression('foo'); - $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); - $this->assertTrue($argumentParser->parseExpression('token.getUser() === null')); - $this->assertTrue($argumentParser->parseExpression('user === null')); - $this->assertTrue($argumentParser->parseExpression('request === null')); + $this->assertSame('fighters', $result); } - public function testRoutingArgumentParser(): void + public function testItMergesVariables(): void { - self::bootKernel(); - - $container = static::getContainer(); + $this->variablesCollection->method('getVariables')->willReturn(['foo' => 'fighters']); - /** @var ArgumentParserInterface $argumentParser */ - $argumentParser = $container->get('sylius.expression_language.argument_parser.routing'); - $this->assertTrue($argumentParser->parseExpression('request === null')); + $result = $this->argumentParser->parseExpression('foo', ['foo' => 'bar']); - $this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser); + $this->assertSame('bar', $result); } } diff --git a/src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php b/src/Component/tests/Symfony/ExpressionLanguage/RequestVariablesTest.php similarity index 100% rename from src/Component/spec/Symfony/ExpressionLanguage/RequestVariablesSpec.php rename to src/Component/tests/Symfony/ExpressionLanguage/RequestVariablesTest.php diff --git a/src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php b/src/Component/tests/Symfony/ExpressionLanguage/TokenVariablesTest.php similarity index 100% rename from src/Component/spec/Symfony/ExpressionLanguage/TokenVariablesSpec.php rename to src/Component/tests/Symfony/ExpressionLanguage/TokenVariablesTest.php diff --git a/src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php b/src/Component/tests/Symfony/ExpressionLanguage/VariablesCollectionTest.php similarity index 100% rename from src/Component/spec/Symfony/ExpressionLanguage/VariablesCollectionSpec.php rename to src/Component/tests/Symfony/ExpressionLanguage/VariablesCollectionTest.php diff --git a/src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php b/src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Form/Factory/FormFactorySpec.php rename to src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php diff --git a/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php b/src/Component/tests/Symfony/Request/RepositoryArgumentResolverTest.php similarity index 100% rename from src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php rename to src/Component/tests/Symfony/Request/RepositoryArgumentResolverTest.php diff --git a/src/Component/spec/Symfony/Request/State/ApiResponderSpec.php b/src/Component/tests/Symfony/Request/State/ApiResponderTest.php similarity index 100% rename from src/Component/spec/Symfony/Request/State/ApiResponderSpec.php rename to src/Component/tests/Symfony/Request/State/ApiResponderTest.php diff --git a/src/Component/spec/Symfony/Request/State/ProviderSpec.php b/src/Component/tests/Symfony/Request/State/ProviderTest.php similarity index 100% rename from src/Component/spec/Symfony/Request/State/ProviderSpec.php rename to src/Component/tests/Symfony/Request/State/ProviderTest.php diff --git a/src/Component/spec/Symfony/Request/State/ResponderSpec.php b/src/Component/tests/Symfony/Request/State/ResponderTest.php similarity index 100% rename from src/Component/spec/Symfony/Request/State/ResponderSpec.php rename to src/Component/tests/Symfony/Request/State/ResponderTest.php diff --git a/src/Component/spec/Symfony/Request/State/TwigResponderSpec.php b/src/Component/tests/Symfony/Request/State/TwigResponderTest.php similarity index 100% rename from src/Component/spec/Symfony/Request/State/TwigResponderSpec.php rename to src/Component/tests/Symfony/Request/State/TwigResponderTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/OperationRouteFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/OperationRouteFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RouteName/OperationRouteNameFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RouteName/OperationRouteNameFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php b/src/Component/tests/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactoryTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactorySpec.php rename to src/Component/tests/Symfony/Routing/Factory/RoutePath/UpdateOperationRoutePathFactoryTest.php diff --git a/src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php b/src/Component/tests/Symfony/Routing/RedirectHandlerTest.php similarity index 100% rename from src/Component/spec/Symfony/Routing/RedirectHandlerSpec.php rename to src/Component/tests/Symfony/Routing/RedirectHandlerTest.php diff --git a/src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php b/src/Component/tests/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php similarity index 100% rename from src/Component/spec/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php rename to src/Component/tests/Symfony/Validator/EventListener/ValidationExceptionListenerSpec.php diff --git a/src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php b/src/Component/tests/Symfony/Validator/Exception/ValidationExceptionSpec.php similarity index 100% rename from src/Component/spec/Symfony/Validator/Exception/ValidationExceptionSpec.php rename to src/Component/tests/Symfony/Validator/Exception/ValidationExceptionSpec.php diff --git a/src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php b/src/Component/tests/Symfony/Workflow/OperationStateMachineTest.php similarity index 100% rename from src/Component/spec/Symfony/Workflow/OperationStateMachineSpec.php rename to src/Component/tests/Symfony/Workflow/OperationStateMachineTest.php From 83fbede1a3f74284b9fa9652ebece0e1116788f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 21 Oct 2024 10:48:53 +0200 Subject: [PATCH 3/3] Fix PHPUnit tests --- src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php b/src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php index 55c31ad4b..47dad0a57 100644 --- a/src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php +++ b/src/Component/tests/Symfony/Form/Factory/FormFactoryTest.php @@ -69,7 +69,7 @@ public function testItCreatesAFormForHtmlRequest(): void ->with('App\Form\DummyType', null, ['foo' => 'fighters']) ->willReturn($form); - $this->assertSame($form, $this->formFactoryInstance->create($operation, new Context(new RequestOption($request->getWrappedObject())))); + $this->assertSame($form, $this->formFactoryInstance->create($operation, new Context(new RequestOption($request)))); } public function testItThrowsAnExceptionWhenOperationHasNoFormType(): void