diff --git a/tests/phpunit/Metadata/Factory/OperationFactoryTest.php b/tests/phpunit/Metadata/Factory/OperationFactoryTest.php index 78aff856f..fc3704402 100644 --- a/tests/phpunit/Metadata/Factory/OperationFactoryTest.php +++ b/tests/phpunit/Metadata/Factory/OperationFactoryTest.php @@ -27,6 +27,7 @@ class OperationFactoryTest extends TestCase public function testCreate(): void { $definition = new GetCollection( + name: 'get_collection', properties: [new Text('my_property')], filters: [new Filter('my_filter')], ); @@ -46,8 +47,8 @@ public function testCreate(): void OperationEvents::OPERATION_CREATED, 'lag_admin.my_resource.operation.create', 'lag_admin.my_resource.operation.created', - 'lag_admin.my_resource.operation.index.create', - 'lag_admin.my_resource.operation.index.created', + 'lag_admin.my_resource.operation.get_collection.create', + 'lag_admin.my_resource.operation.get_collection.created', ]); return $event; diff --git a/tests/phpunit/Metadata/Factory/PropertyFactoryTest.php b/tests/phpunit/Metadata/Factory/PropertyFactoryTest.php index bb6313c15..98245f298 100644 --- a/tests/phpunit/Metadata/Factory/PropertyFactoryTest.php +++ b/tests/phpunit/Metadata/Factory/PropertyFactoryTest.php @@ -24,7 +24,7 @@ class PropertyFactoryTest extends TestCase public function testCreate(): void { $definition = new Text(name: 'my_property'); - $resource = new AdminResource(name: 'a_resource', translationDomain: 'my_domain'); + $resource = new AdminResource(name: 'a_resource', translationDomain: 'my_domain', applicationName: 'app'); $operation = (new GetCollection(properties: [$definition]))->withResource($resource); $this @@ -44,7 +44,7 @@ public function testCreate(): void $this->assertCount(1, $properties); $this->assertArrayHasKey('my_property', $properties); $this->assertEquals('my_property', $properties['my_property']->getName()); - $this->assertEquals('My property', $properties['my_property']->getLabel()); + $this->assertEquals('app.a_resource.my_property', $properties['my_property']->getLabel()); $this->assertEquals('my_domain', $properties['my_property']->getTranslationDomain()); } @@ -53,8 +53,9 @@ public function testCreateWithTranslationPattern(): void $definition = new Text(name: 'my_property'); $resource = new AdminResource( name: 'a_resource', + applicationName: 'app', translationDomain: 'my_domain', - translationPattern: 'test.{resource}.{property}', + translationPattern: 'test.{resource}.{message}', ); $operation = (new GetCollection(properties: [$definition]))->withResource($resource); @@ -82,7 +83,7 @@ public function testCreateWithTranslationPattern(): void public function testCreateInvalid(): void { $definition = new Text(name: 'my_property'); - $resource = new AdminResource(name: 'a_resource', translationDomain: 'my_domain'); + $resource = new AdminResource(applicationName: 'app', name: 'a_resource', translationDomain: 'my_domain'); $operation = (new GetCollection(properties: [$definition]))->withResource($resource); $violations = $this->createMock(ConstraintViolationList::class); diff --git a/tests/phpunit/Metadata/Factory/ResourceFactoryCacheDecoratorTest.php b/tests/phpunit/Metadata/Factory/ResourceFactoryCacheDecoratorTest.php deleted file mode 100644 index a2f2e303c..000000000 --- a/tests/phpunit/Metadata/Factory/ResourceFactoryCacheDecoratorTest.php +++ /dev/null @@ -1,46 +0,0 @@ -decorated - ->expects($this->once()) - ->method('create') - ; - $this->decorator->create($definition); - $this->decorator->create($definition); - } - - public function testCreateWithDifferentName(): void - { - $this - ->decorated - ->expects($this->exactly(2)) - ->method('create') - ; - $this->decorator->create(new AdminResource(name: 'my_resource')); - $this->decorator->create(new AdminResource(name: 'my_other_resource')); - } - - protected function setUp(): void - { - $this->decorated = $this->createMock(ResourceFactoryInterface::class); - $this->decorator = new ResourceFactoryCacheDecorator($this->decorated); - } -} diff --git a/tests/phpunit/Metadata/Locator/CompositeFactoryTest.php b/tests/phpunit/Metadata/Locator/CompositeLocatorTest.php similarity index 56% rename from tests/phpunit/Metadata/Locator/CompositeFactoryTest.php rename to tests/phpunit/Metadata/Locator/CompositeLocatorTest.php index 48f222f41..8a351aa67 100644 --- a/tests/phpunit/Metadata/Locator/CompositeFactoryTest.php +++ b/tests/phpunit/Metadata/Locator/CompositeLocatorTest.php @@ -9,8 +9,10 @@ use LAG\AdminBundle\Metadata\Locator\CompositeLocator; use LAG\AdminBundle\Metadata\Locator\MetadataLocatorInterface; use LAG\AdminBundle\Tests\TestCase; +use Symfony\Component\HttpKernel\Bundle\BundleInterface; +use Symfony\Component\HttpKernel\KernelInterface; -class CompositeFactoryTest extends TestCase +class CompositeLocatorTest extends TestCase { public function testCreateResources(): void { @@ -33,16 +35,49 @@ public function testCreateResources(): void ]) ; - $compositeLocator = $this->createLocator([$locator1, $locator2]); + $kernel = $this->createMock(KernelInterface::class); + + $compositeLocator = $this->createLocator([$locator1, $locator2], $this->createMock(KernelInterface::class)); $this->assertEquals([ new AdminResource('an_admin'), new AdminResource('an_other_admin'), ], $compositeLocator->locateCollection('/a/directory')); } + public function testLocateBundleLocators(): void + { + $locator = $this->createMock(MetadataLocatorInterface::class); + $locator + ->expects($this->once()) + ->method('locateCollection') + ->with('/a/path/to/bundle/Entity') + ->willReturn([ + new AdminResource('an_admin'), + ]) + ; + + $bundle = $this->createMock(BundleInterface::class); + $bundle + ->expects($this->once()) + ->method('getPath') + ->willReturn('/a/path/to/bundle') + ; + + $kernel = $this->createMock(KernelInterface::class); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->with('MyBundle') + ->willReturn($bundle) + ; + + $compositeLocator = $this->createLocator([$locator], $kernel); + $compositeLocator->locateCollection('@MyBundle/Entity'); + } + public function testLocateWithNoLocators(): void { - $compositeLocator = $this->createLocator([]); + $compositeLocator = $this->createLocator([], $this->createMock(KernelInterface::class)); $this->assertEquals([], $compositeLocator->locateCollection('/a/directory')); } @@ -59,12 +94,12 @@ public function testWithWrongLocator(): void ; $this->expectException(Exception::class); - $compositeLocator = $this->createLocator([$wrongLocator]); + $compositeLocator = $this->createLocator([$wrongLocator], $this->createMock(KernelInterface::class)); $compositeLocator->locateCollection('/a/directory'); } - public function createLocator(array $locators): CompositeLocator + public function createLocator(array $locators, KernelInterface $kernel): CompositeLocator { - return new \LAG\AdminBundle\Metadata\Locator\CompositeLocator($locators); + return new CompositeLocator($locators, $kernel); } }