From cf632593cf8018fcb8ca2a0a99ff5e2d8612587c Mon Sep 17 00:00:00 2001 From: Norbert Glanc Date: Mon, 27 Oct 2025 09:53:56 +0100 Subject: [PATCH 1/3] PHPSpec to PHPUnit DependencyInjection --- .../Helper/TargetEntitiesResolverSpec.php | 119 ---------------- .../Exception/InvalidDriverExceptionSpec.php | 34 ----- .../Exception/UnknownDriverExceptionSpec.php | 34 ----- .../Helper/TargetEntitiesResolverTest.php | 134 ++++++++++++++++++ .../Exception/InvalidDriverExceptionTest.php | 35 +++++ .../Exception/UnknownDriverExceptionTest.php | 32 +++++ 6 files changed, 201 insertions(+), 187 deletions(-) delete mode 100644 src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php delete mode 100644 src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php delete mode 100644 src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php create mode 100644 tests/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolverTest.php create mode 100644 tests/Bundle/DependencyInjection/Driver/Exception/InvalidDriverExceptionTest.php create mode 100644 tests/Bundle/DependencyInjection/Driver/Exception/UnknownDriverExceptionTest.php diff --git a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php b/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php deleted file mode 100644 index 07dea17fe..000000000 --- a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php +++ /dev/null @@ -1,119 +0,0 @@ -shouldImplement(TargetEntitiesResolverInterface::class); - } - - function it_skips_resource_interface(): void - { - $emptyConfig = ['app.resource' => ['classes' => ['model' => Resource::class]]]; - - $this->resolve($emptyConfig)->shouldReturn([]); - } - - function it_autodiscovers_interfaces_based_on_the_model_class(): void - { - $flyConfig = ['app.fly' => ['classes' => ['model' => Fly::class]]]; - - $this->resolve($flyConfig)->shouldHaveCount(2); - $this->resolve($flyConfig)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); - $this->resolve($flyConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class); - - $bearConfig = ['app.bear' => ['classes' => ['model' => Bear::class]]]; - - $this->resolve($bearConfig)->shouldHaveCount(3); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class); - } - - function it_autodiscovers_only_unique_interfaces_based_on_model_classes(): void - { - $config = [ - 'app.fly' => ['classes' => ['model' => Fly::class]], - 'app.bear' => ['classes' => ['model' => Bear::class]], - ]; - - $this->resolve($config)->shouldHaveCount(3); - $this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); - - $this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Fly::class); - $this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Bear::class); - } - - function it_autodiscovers_interfaces_on_models_when_passed_multiple_times(): void - { - $config = [ - 'app.fly' => ['classes' => ['model' => Fly::class]], - 'app.another_resource_with_fly_model' => ['classes' => ['model' => Fly::class]], - ]; - - $this->resolve($config)->shouldHaveCount(2); - $this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); - $this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class); - } - - function it_uses_the_interface_defined_in_the_config(): void - { - $config = [ - 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => \Countable::class]], - ]; - - error_reporting(0); - $this->resolve($config)->shouldHaveCount(1); - $this->resolve($config)->shouldHaveKeyWithValue(\Countable::class, Resource::class); - error_reporting(\E_ALL); - $this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]); - } - - function it_uses_the_interface_defined_explicitly_over_the_autodiscovered_one(): void - { - $config = [ - 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => MammalInterface::class]], - 'app.bear' => ['classes' => ['model' => Bear::class]], - ]; - - error_reporting(0); - $this->resolve($config)->shouldHaveCount(3); - $this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Resource::class); - $this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - error_reporting(\E_ALL); - $this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]); - } - - function it_throws_an_exception_if_model_class_can_not_be_resolved(): void - { - $config = ['app.error' => ['classes' => ['interface' => \Countable::class]]]; - - $this->shouldThrow(\InvalidArgumentException::class)->during('resolve', [$config]); - } -} diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php deleted file mode 100644 index 4e29826ed..000000000 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php +++ /dev/null @@ -1,34 +0,0 @@ -beConstructedWith('driver', 'className'); - } - - function it_extends_exception(): void - { - $this->shouldHaveType(\Exception::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Driver "driver" is not supported by className.'); - } -} diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php deleted file mode 100644 index 7330ee3e2..000000000 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php +++ /dev/null @@ -1,34 +0,0 @@ -beConstructedWith('driver'); - } - - function it_extends_exception(): void - { - $this->shouldHaveType(\Exception::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Unknown driver "driver".'); - } -} diff --git a/tests/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolverTest.php b/tests/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolverTest.php new file mode 100644 index 000000000..840d44f69 --- /dev/null +++ b/tests/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolverTest.php @@ -0,0 +1,134 @@ +resolver = new TargetEntitiesResolver(); + } + + public function testItIsATargetEntitiesResolver(): void + { + $this->assertInstanceOf(TargetEntitiesResolverInterface::class, $this->resolver); + } + + public function testItSkipsResourceInterface(): void + { + $emptyConfig = ['app.resource' => ['classes' => ['model' => Resource::class]]]; + + $this->assertSame([], $this->resolver->resolve($emptyConfig)); + } + + public function testItAutodiscoversInterfacesBasedOnTheModelClass(): void + { + $flyConfig = ['app.fly' => ['classes' => ['model' => Fly::class]]]; + + $resolved = $this->resolver->resolve($flyConfig); + + $this->assertCount(2, $resolved); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); + + $bearConfig = ['app.bear' => ['classes' => ['model' => Bear::class]]]; + + $resolved = $this->resolver->resolve($bearConfig); + + $this->assertCount(3, $resolved); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); + $this->assertSame(Bear::class, $resolved[MammalInterface::class]); + $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); + } + + public function testItAutodiscoversOnlyUniqueInterfacesBasedOnModelClasses(): void + { + $config = [ + 'app.fly' => ['classes' => ['model' => Fly::class]], + 'app.bear' => ['classes' => ['model' => Bear::class]], + ]; + + $resolved = $this->resolver->resolve($config); + + $this->assertCount(3, $resolved); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); + $this->assertSame(Bear::class, $resolved[MammalInterface::class]); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + + $this->assertArrayNotHasKey(AnimalInterface::class, $resolved); + } + + public function testItAutodiscoversInterfacesOnModelsWhenPassedMultipleTimes(): void + { + $config = [ + 'app.fly' => ['classes' => ['model' => Fly::class]], + 'app.another_resource_with_fly_model' => ['classes' => ['model' => Fly::class]], + ]; + + $resolved = $this->resolver->resolve($config); + + $this->assertCount(2, $resolved); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); + } + + public function testItUsesTheInterfaceDefinedInTheConfig(): void + { + $config = [ + 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => \Countable::class]], + ]; + + $resolved = @$this->resolver->resolve($config); + + $this->assertCount(1, $resolved); + $this->assertSame(Resource::class, $resolved[\Countable::class]); + } + + public function testItUsesTheInterfaceDefinedExplicitlyOverTheAutodiscoveredOne(): void + { + $config = [ + 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => MammalInterface::class]], + 'app.bear' => ['classes' => ['model' => Bear::class]], + ]; + + $resolved = @$this->resolver->resolve($config); + + $this->assertCount(3, $resolved); + $this->assertSame(Resource::class, $resolved[MammalInterface::class]); + $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); + } + + public function testItThrowsAnExceptionIfModelClassCannotBeResolved(): void + { + $config = ['app.error' => ['classes' => ['interface' => \Countable::class]]]; + + $this->expectException(\InvalidArgumentException::class); + + $this->resolver->resolve($config); + } +} diff --git a/tests/Bundle/DependencyInjection/Driver/Exception/InvalidDriverExceptionTest.php b/tests/Bundle/DependencyInjection/Driver/Exception/InvalidDriverExceptionTest.php new file mode 100644 index 000000000..244ebaab2 --- /dev/null +++ b/tests/Bundle/DependencyInjection/Driver/Exception/InvalidDriverExceptionTest.php @@ -0,0 +1,35 @@ +invalidDriverException = new InvalidDriverException('driver', 'className'); + } + + public function testHasAMessage(): void + { + $this->assertSame( + 'Driver "driver" is not supported by className.', + $this->invalidDriverException->getMessage(), + ); + } +} diff --git a/tests/Bundle/DependencyInjection/Driver/Exception/UnknownDriverExceptionTest.php b/tests/Bundle/DependencyInjection/Driver/Exception/UnknownDriverExceptionTest.php new file mode 100644 index 000000000..b529079ad --- /dev/null +++ b/tests/Bundle/DependencyInjection/Driver/Exception/UnknownDriverExceptionTest.php @@ -0,0 +1,32 @@ +unknownDriverException = new UnknownDriverException('driver'); + } + + public function testHasAMessage(): void + { + $this->assertSame('Unknown driver "driver".', $this->unknownDriverException->getMessage()); + } +} From dfaa96c4480050e766319560aa8de47d60adb6af Mon Sep 17 00:00:00 2001 From: Norbert Glanc Date: Mon, 27 Oct 2025 09:53:56 +0100 Subject: [PATCH 2/3] PHPSpec to PHPUnit DependencyInjection --- .../Helper/TargetEntitiesResolverSpec.php | 99 +++++++++++-------- .../Exception/InvalidDriverExceptionSpec.php | 23 ++--- .../Exception/UnknownDriverExceptionSpec.php | 20 ++-- 3 files changed, 78 insertions(+), 64 deletions(-) diff --git a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php b/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php index 07dea17fe..e9e436f0e 100644 --- a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php +++ b/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php @@ -11,9 +11,10 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper; +namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Compiler\Helper; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolverInterface; use Sylius\Bundle\ResourceBundle\Tests\Fixtures\AnimalInterface; use Sylius\Bundle\ResourceBundle\Tests\Fixtures\Bear; @@ -23,97 +24,111 @@ use Sylius\Bundle\ResourceBundle\Tests\Fixtures\MammalInterface; use Sylius\Bundle\ResourceBundle\Tests\Fixtures\Resource; -class TargetEntitiesResolverSpec extends ObjectBehavior +final class TargetEntitiesResolverTest extends TestCase { - function it_is_a_target_entities_resolver(): void + private TargetEntitiesResolverInterface $resolver; + + protected function setUp(): void + { + $this->resolver = new TargetEntitiesResolver(); + } + + public function testItIsATargetEntitiesResolver(): void { - $this->shouldImplement(TargetEntitiesResolverInterface::class); + $this->assertInstanceOf(TargetEntitiesResolverInterface::class, $this->resolver); } - function it_skips_resource_interface(): void + public function testItSkipsResourceInterface(): void { $emptyConfig = ['app.resource' => ['classes' => ['model' => Resource::class]]]; - $this->resolve($emptyConfig)->shouldReturn([]); + $this->assertSame([], $this->resolver->resolve($emptyConfig)); } - function it_autodiscovers_interfaces_based_on_the_model_class(): void + public function testItAutodiscoversInterfacesBasedOnTheModelClass(): void { $flyConfig = ['app.fly' => ['classes' => ['model' => Fly::class]]]; - $this->resolve($flyConfig)->shouldHaveCount(2); - $this->resolve($flyConfig)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); - $this->resolve($flyConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class); + $resolved = $this->resolver->resolve($flyConfig); + + $this->assertCount(2, $resolved); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); $bearConfig = ['app.bear' => ['classes' => ['model' => Bear::class]]]; - $this->resolve($bearConfig)->shouldHaveCount(3); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class); - $this->resolve($bearConfig)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class); + $resolved = $this->resolver->resolve($bearConfig); + + $this->assertCount(3, $resolved); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); + $this->assertSame(Bear::class, $resolved[MammalInterface::class]); + $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); } - function it_autodiscovers_only_unique_interfaces_based_on_model_classes(): void + public function testItAutodiscoversOnlyUniqueInterfacesBasedOnModelClasses(): void { $config = [ 'app.fly' => ['classes' => ['model' => Fly::class]], 'app.bear' => ['classes' => ['model' => Bear::class]], ]; - $this->resolve($config)->shouldHaveCount(3); - $this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); + $resolved = $this->resolver->resolve($config); - $this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Fly::class); - $this->resolve($config)->shouldNotHaveKeyWithValue(AnimalInterface::class, Bear::class); + $this->assertCount(3, $resolved); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); + $this->assertSame(Bear::class, $resolved[MammalInterface::class]); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + + $this->assertArrayNotHasKey(AnimalInterface::class, $resolved); } - function it_autodiscovers_interfaces_on_models_when_passed_multiple_times(): void + public function testItAutodiscoversInterfacesOnModelsWhenPassedMultipleTimes(): void { $config = [ 'app.fly' => ['classes' => ['model' => Fly::class]], 'app.another_resource_with_fly_model' => ['classes' => ['model' => Fly::class]], ]; - $this->resolve($config)->shouldHaveCount(2); - $this->resolve($config)->shouldHaveKeyWithValue(FlyInterface::class, Fly::class); - $this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Fly::class); + $resolved = $this->resolver->resolve($config); + + $this->assertCount(2, $resolved); + $this->assertSame(Fly::class, $resolved[FlyInterface::class]); + $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); } - function it_uses_the_interface_defined_in_the_config(): void + public function testItUsesTheInterfaceDefinedInTheConfig(): void { $config = [ 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => \Countable::class]], ]; - error_reporting(0); - $this->resolve($config)->shouldHaveCount(1); - $this->resolve($config)->shouldHaveKeyWithValue(\Countable::class, Resource::class); - error_reporting(\E_ALL); - $this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]); + $resolved = @$this->resolver->resolve($config); + + $this->assertCount(1, $resolved); + $this->assertSame(Resource::class, $resolved[\Countable::class]); } - function it_uses_the_interface_defined_explicitly_over_the_autodiscovered_one(): void + public function testItUsesTheInterfaceDefinedExplicitlyOverTheAutodiscoveredOne(): void { $config = [ 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => MammalInterface::class]], 'app.bear' => ['classes' => ['model' => Bear::class]], ]; - error_reporting(0); - $this->resolve($config)->shouldHaveCount(3); - $this->resolve($config)->shouldHaveKeyWithValue(MammalInterface::class, Resource::class); - $this->resolve($config)->shouldHaveKeyWithValue(AnimalInterface::class, Bear::class); - $this->resolve($config)->shouldHaveKeyWithValue(BearInterface::class, Bear::class); - error_reporting(\E_ALL); - $this->shouldTrigger(\E_USER_DEPRECATED)->during('resolve', [$config]); + $resolved = @$this->resolver->resolve($config); + + $this->assertCount(3, $resolved); + $this->assertSame(Resource::class, $resolved[MammalInterface::class]); + $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); + $this->assertSame(Bear::class, $resolved[BearInterface::class]); } - function it_throws_an_exception_if_model_class_can_not_be_resolved(): void + public function testItThrowsAnExceptionIfModelClassCannotBeResolved(): void { $config = ['app.error' => ['classes' => ['interface' => \Countable::class]]]; - $this->shouldThrow(\InvalidArgumentException::class)->during('resolve', [$config]); + $this->expectException(\InvalidArgumentException::class); + + $this->resolver->resolve($config); } } diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php index 4e29826ed..e65ef9768 100644 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php +++ b/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php @@ -11,24 +11,25 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception; +namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Driver\Exception; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\InvalidDriverException; -final class InvalidDriverExceptionSpec extends ObjectBehavior +final class InvalidDriverExceptionTest extends TestCase { - function let(): void - { - $this->beConstructedWith('driver', 'className'); - } + private InvalidDriverException $invalidDriverException; - function it_extends_exception(): void + protected function setUp(): void { - $this->shouldHaveType(\Exception::class); + $this->invalidDriverException = new InvalidDriverException('driver', 'className'); } - function it_has_a_message(): void + public function testHasAMessage(): void { - $this->getMessage()->shouldReturn('Driver "driver" is not supported by className.'); + $this->assertSame( + 'Driver "driver" is not supported by className.', + $this->invalidDriverException->getMessage(), + ); } } diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php index 7330ee3e2..01231c0d6 100644 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php +++ b/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php @@ -11,24 +11,22 @@ declare(strict_types=1); -namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception; +namespace Sylius\Bundle\ResourceBundle\spec\DependencyInjection\Driver\Exception; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\UnknownDriverException; -final class UnknownDriverExceptionSpec extends ObjectBehavior +final class UnknownDriverExceptionTest extends TestCase { - function let(): void - { - $this->beConstructedWith('driver'); - } + private UnknownDriverException $unknownDriverException; - function it_extends_exception(): void + protected function setUp(): void { - $this->shouldHaveType(\Exception::class); + $this->unknownDriverException = new UnknownDriverException('driver'); } - function it_has_a_message(): void + public function testHasAMessage(): void { - $this->getMessage()->shouldReturn('Unknown driver "driver".'); + $this->assertSame('Unknown driver "driver".', $this->unknownDriverException->getMessage()); } } From 157ea1817bf996710b998de113539fcb9b66541b Mon Sep 17 00:00:00 2001 From: Norbert Glanc Date: Fri, 31 Oct 2025 07:58:50 +0100 Subject: [PATCH 3/3] Move phpunit tests to the proper directory --- .../Helper/TargetEntitiesResolverSpec.php | 134 ------------------ .../Exception/InvalidDriverExceptionSpec.php | 35 ----- .../Exception/UnknownDriverExceptionSpec.php | 32 ----- 3 files changed, 201 deletions(-) delete mode 100644 src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php delete mode 100644 src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php delete mode 100644 src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php diff --git a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php b/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php deleted file mode 100644 index e9e436f0e..000000000 --- a/src/Bundle/spec/DependencyInjection/Compiler/Helper/TargetEntitiesResolverSpec.php +++ /dev/null @@ -1,134 +0,0 @@ -resolver = new TargetEntitiesResolver(); - } - - public function testItIsATargetEntitiesResolver(): void - { - $this->assertInstanceOf(TargetEntitiesResolverInterface::class, $this->resolver); - } - - public function testItSkipsResourceInterface(): void - { - $emptyConfig = ['app.resource' => ['classes' => ['model' => Resource::class]]]; - - $this->assertSame([], $this->resolver->resolve($emptyConfig)); - } - - public function testItAutodiscoversInterfacesBasedOnTheModelClass(): void - { - $flyConfig = ['app.fly' => ['classes' => ['model' => Fly::class]]]; - - $resolved = $this->resolver->resolve($flyConfig); - - $this->assertCount(2, $resolved); - $this->assertSame(Fly::class, $resolved[FlyInterface::class]); - $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); - - $bearConfig = ['app.bear' => ['classes' => ['model' => Bear::class]]]; - - $resolved = $this->resolver->resolve($bearConfig); - - $this->assertCount(3, $resolved); - $this->assertSame(Bear::class, $resolved[BearInterface::class]); - $this->assertSame(Bear::class, $resolved[MammalInterface::class]); - $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); - } - - public function testItAutodiscoversOnlyUniqueInterfacesBasedOnModelClasses(): void - { - $config = [ - 'app.fly' => ['classes' => ['model' => Fly::class]], - 'app.bear' => ['classes' => ['model' => Bear::class]], - ]; - - $resolved = $this->resolver->resolve($config); - - $this->assertCount(3, $resolved); - $this->assertSame(Bear::class, $resolved[BearInterface::class]); - $this->assertSame(Bear::class, $resolved[MammalInterface::class]); - $this->assertSame(Fly::class, $resolved[FlyInterface::class]); - - $this->assertArrayNotHasKey(AnimalInterface::class, $resolved); - } - - public function testItAutodiscoversInterfacesOnModelsWhenPassedMultipleTimes(): void - { - $config = [ - 'app.fly' => ['classes' => ['model' => Fly::class]], - 'app.another_resource_with_fly_model' => ['classes' => ['model' => Fly::class]], - ]; - - $resolved = $this->resolver->resolve($config); - - $this->assertCount(2, $resolved); - $this->assertSame(Fly::class, $resolved[FlyInterface::class]); - $this->assertSame(Fly::class, $resolved[AnimalInterface::class]); - } - - public function testItUsesTheInterfaceDefinedInTheConfig(): void - { - $config = [ - 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => \Countable::class]], - ]; - - $resolved = @$this->resolver->resolve($config); - - $this->assertCount(1, $resolved); - $this->assertSame(Resource::class, $resolved[\Countable::class]); - } - - public function testItUsesTheInterfaceDefinedExplicitlyOverTheAutodiscoveredOne(): void - { - $config = [ - 'app.deprecated' => ['classes' => ['model' => Resource::class, 'interface' => MammalInterface::class]], - 'app.bear' => ['classes' => ['model' => Bear::class]], - ]; - - $resolved = @$this->resolver->resolve($config); - - $this->assertCount(3, $resolved); - $this->assertSame(Resource::class, $resolved[MammalInterface::class]); - $this->assertSame(Bear::class, $resolved[AnimalInterface::class]); - $this->assertSame(Bear::class, $resolved[BearInterface::class]); - } - - public function testItThrowsAnExceptionIfModelClassCannotBeResolved(): void - { - $config = ['app.error' => ['classes' => ['interface' => \Countable::class]]]; - - $this->expectException(\InvalidArgumentException::class); - - $this->resolver->resolve($config); - } -} diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php deleted file mode 100644 index e65ef9768..000000000 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/InvalidDriverExceptionSpec.php +++ /dev/null @@ -1,35 +0,0 @@ -invalidDriverException = new InvalidDriverException('driver', 'className'); - } - - public function testHasAMessage(): void - { - $this->assertSame( - 'Driver "driver" is not supported by className.', - $this->invalidDriverException->getMessage(), - ); - } -} diff --git a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php b/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php deleted file mode 100644 index 01231c0d6..000000000 --- a/src/Bundle/spec/DependencyInjection/Driver/Exception/UnknownDriverExceptionSpec.php +++ /dev/null @@ -1,32 +0,0 @@ -unknownDriverException = new UnknownDriverException('driver'); - } - - public function testHasAMessage(): void - { - $this->assertSame('Unknown driver "driver".', $this->unknownDriverException->getMessage()); - } -}