Skip to content

Commit

Permalink
tests: update metadata factories tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkrovitch committed Oct 28, 2023
1 parent c05769b commit 07cf5ca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 58 deletions.
5 changes: 3 additions & 2 deletions tests/phpunit/Metadata/Factory/OperationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
);
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/Metadata/Factory/PropertyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'));
}

Expand All @@ -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);
}
}

0 comments on commit 07cf5ca

Please sign in to comment.