From 42a901f3f538a92128250fd080d4f2596dc0e851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 11 Sep 2024 23:33:18 +0200 Subject: [PATCH 1/2] [phpspec-2-phpunit] migration of tests (State) --- src/Component/spec/State/FactorySpec.php | 131 ++++++++---------- .../Processor/BulkAwareProcessorSpec.php | 58 ++++---- .../EventDispatcherBulkAwareProcessorSpec.php | 47 ++++--- src/Component/spec/State/ProcessorSpec.php | 66 +++++---- src/Component/spec/State/ProviderSpec.php | 64 +++++---- src/Component/spec/State/ResponderSpec.php | 65 +++++---- 6 files changed, 235 insertions(+), 196 deletions(-) diff --git a/src/Component/spec/State/FactorySpec.php b/src/Component/spec/State/FactorySpec.php index bae0106e3..56a2e10c7 100644 --- a/src/Component/spec/State/FactorySpec.php +++ b/src/Component/spec/State/FactorySpec.php @@ -11,9 +11,11 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State; +namespace Sylius\Resource\Tests\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Sylius\Resource\Context\Context; use Sylius\Resource\Factory\FactoryInterface; @@ -21,107 +23,87 @@ use Sylius\Resource\State\Factory; use Sylius\Resource\Symfony\ExpressionLanguage\ArgumentParserInterface; -final class FactorySpec extends ObjectBehavior +final class FactoryTest extends TestCase { - function let( - ContainerInterface $locator, - ArgumentParserInterface $argumentParser, - ): void { - $this->beConstructedWith($locator, $argumentParser); - } + use ProphecyTrait; - function it_is_initializable(): void - { - $this->shouldHaveType(Factory::class); - } + private Factory $factory; - function it_calls_factory_from_operation_as_callable(): void - { - $factory = [FactoryCallable::class, 'create']; + private ContainerInterface|ObjectProphecy $locator; - $operation = new Create(factory: $factory); + private ArgumentParserInterface|ObjectProphecy $argumentParser; - $this->create($operation, new Context())->shouldHaveType(\stdClass::class); + protected function setUp(): void + { + $this->locator = $this->prophesize(ContainerInterface::class); + $this->argumentParser = $this->prophesize(ArgumentParserInterface::class); + $this->factory = new Factory($this->locator->reveal(), $this->argumentParser->reveal()); } - function it_calls_factory_with_arguments_from_operation_as_callable( - ArgumentParserInterface $argumentParser, - ): void { - $factory = [FactoryCallable::class, 'create']; - - $operation = new Create(factory: $factory, factoryArguments: ['userId' => 'user.getUserIdentifier()']); + public function testItIsInitializable(): void + { + $this->assertInstanceOf(Factory::class, $this->factory); + } - $argumentParser->parseExpression('user.getUserIdentifier()')->willReturn('51353e91-5295-4876-a994-cae4b3ff3a7c'); + public function testItCallsFactoryFromOperationAsCallable(): void + { + $operation = new Create(factory: [FactoryCallable::class, 'create']); + $result = $this->factory->create($operation, new Context()); - $result = $this->create($operation, new Context()); - $result->shouldHaveType(\stdClass::class); - $result->userId->shouldReturn('51353e91-5295-4876-a994-cae4b3ff3a7c'); + $this->assertInstanceOf(\stdClass::class, $result); } - function it_calls_factory_from_operation_as_string( - FactoryInterface $factory, - ContainerInterface $locator, - \stdClass $data, - ): void { - $operation = new Create(name: 'app_dummy_create', factory: $factory::class, factoryMethod: 'createNew'); - - $locator->has($factory::class)->willReturn(true); - $locator->get($factory::class)->willReturn($factory); + public function testItCallsFactoryWithArgumentsFromOperationAsCallable(): void + { + $operation = new Create(factory: [FactoryCallable::class, 'create'], factoryArguments: ['userId' => 'user.getUserIdentifier()']); + $this->argumentParser->parseExpression('user.getUserIdentifier()')->willReturn('51353e91-5295-4876-a994-cae4b3ff3a7c'); - $factory->createNew()->willReturn($data); + $result = $this->factory->create($operation, new Context()); - $this->create($operation, new Context())->shouldReturn($data); + $this->assertInstanceOf(\stdClass::class, $result); + $this->assertEquals('51353e91-5295-4876-a994-cae4b3ff3a7c', $result->userId); } - function it_throws_an_exception_when_factory_is_not_found_on_locator( - FactoryInterface $factory, - ContainerInterface $locator, - \stdClass $data, - ): void { - $operation = new Create(name: 'app_dummy_create', factory: $factory::class, factoryMethod: 'createNew'); - - $locator->has($factory::class)->willReturn(false); - $locator->get($factory::class)->willReturn($factory); + public function testItCallsFactoryFromOperationAsString(): void + { + $factory = $this->prophesize(FactoryInterface::class); + $operation = new Create(name: 'app_dummy_create', factory: get_class($factory->reveal()), factoryMethod: 'createNew'); + $data = new \stdClass(); + $this->locator->has(get_class($factory->reveal()))->willReturn(true); + $this->locator->get(get_class($factory->reveal()))->willReturn($factory->reveal()); $factory->createNew()->willReturn($data); - $this->shouldThrow( - new \RuntimeException(sprintf('Factory "%s" not found on operation "app_dummy_create"', $factory::class)), - )->during('create', [$operation, new Context()]); + $result = $this->factory->create($operation, new Context()); + + $this->assertSame($data, $result); } - function it_throws_an_exception_when_factory_method_is_null( - FactoryInterface $factory, - ContainerInterface $locator, - \stdClass $data, - ): void { - $operation = new Create(name: 'app_dummy_create', factory: $factory::class); + public function testItThrowsExceptionWhenFactoryIsNotFoundOnLocator(): void + { + $factory = $this->prophesize(FactoryInterface::class); + $operation = new Create(name: 'app_dummy_create', factory: get_class($factory->reveal()), factoryMethod: 'createNew'); - $locator->has($factory::class)->willReturn(true); - $locator->get($factory::class)->willReturn($factory); + $this->locator->has(get_class($factory->reveal()))->willReturn(false); - $factory->createNew()->willReturn($data); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage(sprintf('Factory "%s" not found on operation "app_dummy_create"', get_class($factory->reveal()))); - $this->shouldThrow( - new \RuntimeException('No Factory method was configured on operation "app_dummy_create"'), - )->during('create', [$operation, new Context()]); + $this->factory->create($operation, new Context()); } -} -final class ResourceFactory implements FactoryInterface -{ - public function createNew(): object + public function testItThrowsExceptionWhenFactoryMethodIsNull(): void { - return new \stdClass(); - } + $factory = $this->prophesize(FactoryInterface::class); + $operation = new Create(name: 'app_dummy_create', factory: get_class($factory->reveal())); - public function createForUser(string $userId): object - { - $object = $this->createNew(); + $this->locator->has(get_class($factory->reveal()))->willReturn(true); + $this->locator->get(get_class($factory->reveal()))->willReturn($factory->reveal()); - $object->userId = $userId; + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('No Factory method was configured on operation "app_dummy_create"'); - return $object; + $this->factory->create($operation, new Context()); } } @@ -130,7 +112,6 @@ final class FactoryCallable public static function create(?string $userId = null): object { $object = new \stdClass(); - $object->userId = $userId; return $object; diff --git a/src/Component/spec/State/Processor/BulkAwareProcessorSpec.php b/src/Component/spec/State/Processor/BulkAwareProcessorSpec.php index 2ece6bd26..a34896986 100644 --- a/src/Component/spec/State/Processor/BulkAwareProcessorSpec.php +++ b/src/Component/spec/State/Processor/BulkAwareProcessorSpec.php @@ -11,9 +11,10 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State\Processor; +namespace Sylius\Resource\Tests\State\Processor; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sylius\Resource\Context\Context; use Sylius\Resource\Metadata\Api\Delete; use Sylius\Resource\Metadata\BulkDelete; @@ -21,47 +22,52 @@ use Sylius\Resource\State\ProcessorInterface; use Sylius\Resource\Symfony\EventDispatcher\OperationEventDispatcherInterface; -final class BulkAwareProcessorSpec extends ObjectBehavior +final class BulkAwareProcessorTest extends TestCase { - function let(ProcessorInterface $processor, OperationEventDispatcherInterface $operationEventDispatcher): void + use ProphecyTrait; + + private BulkAwareProcessor $bulkAwareProcessor; + + private $processor; + + private $operationEventDispatcher; + + protected function setUp(): void { - $this->beConstructedWith($processor, $operationEventDispatcher); + $this->processor = $this->prophesize(ProcessorInterface::class); + $this->operationEventDispatcher = $this->prophesize(OperationEventDispatcherInterface::class); + $this->bulkAwareProcessor = new BulkAwareProcessor($this->processor->reveal(), $this->operationEventDispatcher->reveal()); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(BulkAwareProcessor::class); + $this->assertInstanceOf(BulkAwareProcessor::class, $this->bulkAwareProcessor); } - function it_calls_decorated_processor_for_each_data_for_bulk_operation( - ProcessorInterface $processor, - \stdClass $firstItem, - \stdClass $secondItem, - ): void { + public function testItCallsDecoratedProcessorForEachDataForBulkOperation(): void + { + $firstItem = new \stdClass(); + $secondItem = new \stdClass(); $operation = new BulkDelete(); $context = new Context(); - $data = [ - $firstItem->getWrappedObject(), - $secondItem->getWrappedObject(), - ]; + $this->processor->process($firstItem, $operation, $context)->willReturn(null)->shouldBeCalled(); + $this->processor->process($secondItem, $operation, $context)->willReturn(null)->shouldBeCalled(); - $processor->process($firstItem, $operation, $context)->willReturn(null)->shouldBeCalled(); - $processor->process($secondItem, $operation, $context)->willReturn(null)->shouldBeCalled(); + $data = [$firstItem, $secondItem]; - $this->process($data, $operation, $context)->shouldReturn(null); + $this->bulkAwareProcessor->process($data, $operation, $context); } - function it_calls_decorated_processor_for_data_for_other_operation_than_bulk_one( - ProcessorInterface $processor, - \stdClass $data, - \stdClass $result, - ): void { + public function testItCallsDecoratedProcessorForDataForOtherOperationThanBulkOne(): void + { + $data = new \stdClass(); + $result = new \stdClass(); $operation = new Delete(); $context = new Context(); - $processor->process($data, $operation, $context)->willReturn($result)->shouldBeCalled(); + $this->processor->process($data, $operation, $context)->willReturn($result)->shouldBeCalled(); - $this->process($data, $operation, $context)->shouldReturn($result); + $this->assertSame($result, $this->bulkAwareProcessor->process($data, $operation, $context)); } } diff --git a/src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php b/src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php index ecc2ea5ea..6c61e6d8d 100644 --- a/src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php +++ b/src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php @@ -11,9 +11,11 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State\Processor; +namespace Sylius\Resource\Tests\State\Processor; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; use Sylius\Component\Resource\Tests\Dummy\ProcessorWithCallable; use Sylius\Resource\Context\Context; use Sylius\Resource\Metadata\BulkDelete; @@ -22,33 +24,46 @@ use Sylius\Resource\Symfony\EventDispatcher\OperationEvent; use Sylius\Resource\Symfony\EventDispatcher\OperationEventDispatcherInterface; -final class EventDispatcherBulkAwareProcessorSpec extends ObjectBehavior +final class EventDispatcherBulkAwareProcessorTest extends TestCase { - function let(ProcessorInterface $decorated, OperationEventDispatcherInterface $operationEventDispatcher): void + use ProphecyTrait; + + private EventDispatcherBulkAwareProcessor $processor; + + private ProcessorInterface|ObjectProphecy $decorated; + + private OperationEventDispatcherInterface|ObjectProphecy $operationEventDispatcher; + + protected function setUp(): void { - $this->beConstructedWith($decorated, $operationEventDispatcher); + $this->decorated = $this->prophesize(ProcessorInterface::class); + $this->operationEventDispatcher = $this->prophesize(OperationEventDispatcherInterface::class); + $this->processor = new EventDispatcherBulkAwareProcessor( + $this->decorated->reveal(), + $this->operationEventDispatcher->reveal(), + ); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(EventDispatcherBulkAwareProcessor::class); + $this->assertInstanceOf(EventDispatcherBulkAwareProcessor::class, $this->processor); } - function it_dispatches_events_for_bulk_operation( - ProcessorInterface $decorated, - OperationEventDispatcherInterface $operationEventDispatcher, - ): void { + public function testItDispatchesEventsForBulkOperation(): void + { $operation = new BulkDelete(processor: [ProcessorWithCallable::class, 'process']); $context = new Context(); - $operationEvent = new OperationEvent(); - $data = []; - $operationEventDispatcher->dispatchBulkEvent($data, $operation, $context)->willReturn($operationEvent)->shouldBeCalled(); + $this->operationEventDispatcher->dispatchBulkEvent($data, $operation, $context) + ->willReturn($operationEvent) + ->shouldBeCalled(); - $decorated->process($data, $operation, $context)->willReturn(null)->shouldBeCalled(); + $this->decorated->process($data, $operation, $context) + ->willReturn(null) + ->shouldBeCalled(); - $this->process($data, $operation, $context); + $this->processor->process($data, $operation, $context); } } diff --git a/src/Component/spec/State/ProcessorSpec.php b/src/Component/spec/State/ProcessorSpec.php index 64a42fc0a..02c547815 100644 --- a/src/Component/spec/State/ProcessorSpec.php +++ b/src/Component/spec/State/ProcessorSpec.php @@ -11,9 +11,11 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State; +namespace Sylius\Resource\Tests\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Sylius\Component\Resource\Tests\Dummy\ProcessorWithCallable; use Sylius\Resource\Context\Context; @@ -21,60 +23,70 @@ use Sylius\Resource\State\Processor; use Sylius\Resource\State\ProcessorInterface; -final class ProcessorSpec extends ObjectBehavior +final class ProcessorTest extends TestCase { - function let(ContainerInterface $locator): void + use ProphecyTrait; + + private Processor $processor; + + private ContainerInterface|ObjectProphecy $locator; + + protected function setUp(): void { - $this->beConstructedWith($locator); + $this->locator = $this->prophesize(ContainerInterface::class); + $this->processor = new Processor($this->locator->reveal()); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(Processor::class); + $this->assertInstanceOf(Processor::class, $this->processor); } - function it_calls_process_method_from_operation_processor_as_string( - ContainerInterface $locator, - ProcessorInterface $processor, - ): void { + public function testItCallsProcessMethodFromOperationProcessorAsString(): void + { $operation = new Create(processor: '\App\Processor'); $context = new Context(); + $processor = $this->prophesize(ProcessorInterface::class); - $locator->has('\App\Processor')->willReturn(true); - $locator->get('\App\Processor')->willReturn($processor); + $this->locator->has('\App\Processor')->willReturn(true); + $this->locator->get('\App\Processor')->willReturn($processor->reveal()); - $processor->process([], $operation, $context)->willReturn(null)->shouldBeCalled(); + $processor->process([], $operation, $context)->shouldBeCalled()->willReturn(null); - $this->process([], $operation, $context); + $this->processor->process([], $operation, $context); } - function it_calls_process_method_from_operation_processor_as_callable(): void + public function testItCallsProcessMethodFromOperationProcessorAsCallable(): void { $operation = new Create(processor: [ProcessorWithCallable::class, 'process']); $context = new Context(); - $this->process([], $operation, $context)->shouldHaveType(\stdClass::class); + $result = $this->processor->process([], $operation, $context); + + $this->assertInstanceOf(\stdClass::class, $result); } - function it_returns_null_if_operation_has_no_processor(): void + public function testItReturnsNullIfOperationHasNoProcessor(): void { $operation = new Create(); $context = new Context(); - $this->process([], $operation, $context)->shouldReturn(null); + $result = $this->processor->process([], $operation, $context); + + $this->assertNull($result); } - function it_throws_an_exception_when_configured_processor_is_not_a_processor_instance( - ContainerInterface $locator, - ): void { + public function testItThrowsExceptionWhenConfiguredProcessorIsNotAProcessorInstance(): void + { $operation = new Create(processor: '\stdClass'); $context = new Context(); - $locator->has('\stdClass')->willReturn(true); - $locator->get('\stdClass')->willReturn(new \stdClass()); + $this->locator->has('\stdClass')->willReturn(true); + $this->locator->get('\stdClass')->willReturn(new \stdClass()); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Expected an instance of Sylius\Resource\State\ProcessorInterface. Got: stdClass'); - $this->shouldThrow(new \InvalidArgumentException('Expected an instance of Sylius\Resource\State\ProcessorInterface. Got: stdClass')) - ->during('process', [[], $operation, $context]) - ; + $this->processor->process([], $operation, $context); } } diff --git a/src/Component/spec/State/ProviderSpec.php b/src/Component/spec/State/ProviderSpec.php index 5cacd0110..e3e6ae9b5 100644 --- a/src/Component/spec/State/ProviderSpec.php +++ b/src/Component/spec/State/ProviderSpec.php @@ -11,9 +11,11 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State; +namespace Sylius\Resource\Tests\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Sylius\Component\Resource\Tests\Dummy\ProviderWithCallable; use Sylius\Resource\Context\Context; @@ -21,60 +23,70 @@ use Sylius\Resource\State\Provider; use Sylius\Resource\State\ProviderInterface; -final class ProviderSpec extends ObjectBehavior +final class ProviderTest extends TestCase { - function let(ContainerInterface $locator): void + use ProphecyTrait; + + private Provider $provider; + + private ContainerInterface|ObjectProphecy $locator; + + protected function setUp(): void { - $this->beConstructedWith($locator); + $this->locator = $this->prophesize(ContainerInterface::class); + $this->provider = new Provider($this->locator->reveal()); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(Provider::class); + $this->assertInstanceOf(Provider::class, $this->provider); } - function it_calls_provide_method_from_operation_provider_as_string( - ContainerInterface $locator, - ProviderInterface $provider, - ): void { + public function testItCallsProvideMethodFromOperationProviderAsString(): void + { $operation = new Create(provider: '\App\Provider'); $context = new Context(); + $provider = $this->prophesize(ProviderInterface::class); - $locator->has('\App\Provider')->willReturn(true); - $locator->get('\App\Provider')->willReturn($provider); + $this->locator->has('\App\Provider')->willReturn(true); + $this->locator->get('\App\Provider')->willReturn($provider->reveal()); $provider->provide($operation, $context)->shouldBeCalled(); - $this->provide($operation, $context); + $this->provider->provide($operation, $context); } - function it_calls_provide_method_from_operation_provider_as_callable(): void + public function testItCallsProvideMethodFromOperationProviderAsCallable(): void { $operation = new Create(provider: [ProviderWithCallable::class, 'provide']); $context = new Context(); - $this->provide($operation, $context)->shouldHaveType(\stdClass::class); + $result = $this->provider->provide($operation, $context); + + $this->assertInstanceOf(\stdClass::class, $result); } - function it_returns_null_if_operation_has_no_provider(): void + public function testItReturnsNullIfOperationHasNoProvider(): void { $operation = new Create(); $context = new Context(); - $this->provide($operation, $context)->shouldReturn(null); + $result = $this->provider->provide($operation, $context); + + $this->assertNull($result); } - function it_throws_an_exception_when_configured_provider_is_not_a_provider_instance( - ContainerInterface $locator, - ): void { + public function testItThrowsExceptionWhenConfiguredProviderIsNotAProviderInstance(): void + { $operation = new Create(provider: '\stdClass'); $context = new Context(); - $locator->has('\stdClass')->willReturn(true); - $locator->get('\stdClass')->willReturn(new \stdClass()); + $this->locator->has('\stdClass')->willReturn(true); + $this->locator->get('\stdClass')->willReturn(new \stdClass()); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Expected an instance of Sylius\Resource\State\ProviderInterface. Got: stdClass'); - $this->shouldThrow(new \InvalidArgumentException('Expected an instance of Sylius\Resource\State\ProviderInterface. Got: stdClass')) - ->during('provide', [$operation, $context]) - ; + $this->provider->provide($operation, $context); } } diff --git a/src/Component/spec/State/ResponderSpec.php b/src/Component/spec/State/ResponderSpec.php index 85af7b165..7b11f89d7 100644 --- a/src/Component/spec/State/ResponderSpec.php +++ b/src/Component/spec/State/ResponderSpec.php @@ -11,9 +11,11 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\State; +namespace Sylius\Resource\Tests\State; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Sylius\Component\Resource\Tests\Dummy\ResponderWithCallable; use Sylius\Resource\Context\Context; @@ -22,60 +24,71 @@ use Sylius\Resource\State\ResponderInterface; use Symfony\Component\HttpFoundation\Response; -final class ResponderSpec extends ObjectBehavior +final class ResponderTest extends TestCase { - function let(ContainerInterface $locator): void + use ProphecyTrait; + + private Responder $responder; + + private ContainerInterface|ObjectProphecy $locator; + + protected function setUp(): void { - $this->beConstructedWith($locator); + $this->locator = $this->prophesize(ContainerInterface::class); + $this->responder = new Responder($this->locator->reveal()); } - function it_is_initializable(): void + public function testItIsInitializable(): void { - $this->shouldHaveType(Responder::class); + $this->assertInstanceOf(Responder::class, $this->responder); } - function it_calls_respond_method_from_operation_responder_as_string( - ContainerInterface $locator, - ResponderInterface $responder, - ): void { + public function testItCallsRespondMethodFromOperationResponderAsString(): void + { $operation = new Create(responder: '\App\Responder'); $context = new Context(); + $responder = $this->prophesize(ResponderInterface::class); - $locator->has('\App\Responder')->willReturn(true); - $locator->get('\App\Responder')->willReturn($responder); + $this->locator->has('\App\Responder')->willReturn(true); + $this->locator->get('\App\Responder')->willReturn($responder->reveal()); $responder->respond([], $operation, $context)->willReturn('response_data')->shouldBeCalled(); - $this->respond([], $operation, $context); + $result = $this->responder->respond([], $operation, $context); + $this->assertEquals('response_data', $result); } - function it_calls_process_method_from_operation_processor_as_callable(): void + public function testItCallsRespondMethodFromOperationResponderAsCallable(): void { $operation = new Create(responder: [ResponderWithCallable::class, 'respond']); $context = new Context(); - $this->respond([], $operation, $context)->shouldHaveType(Response::class); + $result = $this->responder->respond([], $operation, $context); + + $this->assertInstanceOf(Response::class, $result); } - function it_returns_null_if_operation_has_no_responder(): void + public function testItReturnsNullIfOperationHasNoResponder(): void { $operation = new Create(); $context = new Context(); - $this->respond([], $operation, $context)->shouldReturn(null); + $result = $this->responder->respond([], $operation, $context); + + $this->assertNull($result); } - function it_throws_an_exception_when_configured_responder_is_not_a_responder_instance( - ContainerInterface $locator, - ): void { + public function testItThrowsExceptionWhenConfiguredResponderIsNotAResponderInstance(): void + { $operation = new Create(responder: '\stdClass'); $context = new Context(); - $locator->has('\stdClass')->willReturn(true); - $locator->get('\stdClass')->willReturn(new \stdClass()); + $this->locator->has('\stdClass')->willReturn(true); + $this->locator->get('\stdClass')->willReturn(new \stdClass()); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Expected an instance of Sylius\Resource\State\ResponderInterface. Got: stdClass'); - $this->shouldThrow(new \InvalidArgumentException('Expected an instance of Sylius\Resource\State\ResponderInterface. Got: stdClass')) - ->during('respond', [[], $operation, $context]) - ; + $this->responder->respond([], $operation, $context); } } From f30d2618beb7fae3e531492880415561c73ba834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 11 Sep 2024 23:36:00 +0200 Subject: [PATCH 2/2] Move tests --- .../{spec/State/FactorySpec.php => tests/State/FactoryTest.php} | 0 .../State/Processor/BulkAwareProcessorTest.php} | 0 .../State/Processor/EventDispatcherBulkAwareProcessorTest.php} | 0 .../State/ProcessorSpec.php => tests/State/ProcessorTest.php} | 0 .../{spec/State/ProviderSpec.php => tests/State/ProviderTest.php} | 0 .../State/ResponderSpec.php => tests/State/ResponderTest.php} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/Component/{spec/State/FactorySpec.php => tests/State/FactoryTest.php} (100%) rename src/Component/{spec/State/Processor/BulkAwareProcessorSpec.php => tests/State/Processor/BulkAwareProcessorTest.php} (100%) rename src/Component/{spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php => tests/State/Processor/EventDispatcherBulkAwareProcessorTest.php} (100%) rename src/Component/{spec/State/ProcessorSpec.php => tests/State/ProcessorTest.php} (100%) rename src/Component/{spec/State/ProviderSpec.php => tests/State/ProviderTest.php} (100%) rename src/Component/{spec/State/ResponderSpec.php => tests/State/ResponderTest.php} (100%) diff --git a/src/Component/spec/State/FactorySpec.php b/src/Component/tests/State/FactoryTest.php similarity index 100% rename from src/Component/spec/State/FactorySpec.php rename to src/Component/tests/State/FactoryTest.php diff --git a/src/Component/spec/State/Processor/BulkAwareProcessorSpec.php b/src/Component/tests/State/Processor/BulkAwareProcessorTest.php similarity index 100% rename from src/Component/spec/State/Processor/BulkAwareProcessorSpec.php rename to src/Component/tests/State/Processor/BulkAwareProcessorTest.php diff --git a/src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php b/src/Component/tests/State/Processor/EventDispatcherBulkAwareProcessorTest.php similarity index 100% rename from src/Component/spec/State/Processor/EventDispatcherBulkAwareProcessorSpec.php rename to src/Component/tests/State/Processor/EventDispatcherBulkAwareProcessorTest.php diff --git a/src/Component/spec/State/ProcessorSpec.php b/src/Component/tests/State/ProcessorTest.php similarity index 100% rename from src/Component/spec/State/ProcessorSpec.php rename to src/Component/tests/State/ProcessorTest.php diff --git a/src/Component/spec/State/ProviderSpec.php b/src/Component/tests/State/ProviderTest.php similarity index 100% rename from src/Component/spec/State/ProviderSpec.php rename to src/Component/tests/State/ProviderTest.php diff --git a/src/Component/spec/State/ResponderSpec.php b/src/Component/tests/State/ResponderTest.php similarity index 100% rename from src/Component/spec/State/ResponderSpec.php rename to src/Component/tests/State/ResponderTest.php