Skip to content

Commit

Permalink
Updated storage mapper test to cover cases using a closure and cases …
Browse files Browse the repository at this point in the history
…using an invokable class
  • Loading branch information
DamienHarper committed Mar 31, 2022
1 parent 2262349 commit 53ad1c9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/Provider/Doctrine/DoctrineProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ public function testSetStorageMapper(): void
self::assertNull($provider->getConfiguration()->getStorageMapper(), 'Mapping closure is not set.');

$provider->setStorageMapper(static fn (string $entity, array $storageServices): StorageServiceInterface => 0 === mb_strpos($entity, 'Foo') ? $storageServices['EM1'] : $storageServices['EM2']);

self::assertNotNull($provider->getConfiguration()->getStorageMapper(), 'Mapping closure is set.');

self::assertSame($entityManager1, $provider->getStorageServiceForEntity('Foo1')->getEntityManager(), 'EM1 is used.');
self::assertSame($entityManager1, $provider->getStorageServiceForEntity('Foo2')->getEntityManager(), 'EM1 is used.');
self::assertSame($entityManager2, $provider->getStorageServiceForEntity('Bar1')->getEntityManager(), 'EM2 is used.');
self::assertSame($entityManager2, $provider->getStorageServiceForEntity('Bar2')->getEntityManager(), 'EM2 is used.');

$provider->setStorageMapper(new FakeStorageMapper());
self::assertNotNull($provider->getConfiguration()->getStorageMapper(), 'StorageMapper is set.');

self::assertSame($entityManager1, $provider->getStorageServiceForEntity('Foo1')->getEntityManager(), 'EM1 is used.');
self::assertSame($entityManager1, $provider->getStorageServiceForEntity('Foo2')->getEntityManager(), 'EM1 is used.');
self::assertSame($entityManager2, $provider->getStorageServiceForEntity('Bar1')->getEntityManager(), 'EM2 is used.');
self::assertSame($entityManager2, $provider->getStorageServiceForEntity('Bar2')->getEntityManager(), 'EM2 is used.');
}

public function testCheckStorageMapperThrowsExceptionWhenNoMapperDefined(): void
Expand Down Expand Up @@ -516,6 +523,14 @@ public function testSetRoleChecker(): void
}
}

class FakeStorageMapper
{
public function __invoke(string $entity, array $storageServices): StorageServiceInterface
{
return 0 === mb_strpos($entity, 'Foo') ? $storageServices['EM1'] : $storageServices['EM2'];
}
}

class FakeUserProvider implements UserProviderInterface
{
public function __invoke(): ?UserInterface
Expand Down

0 comments on commit 53ad1c9

Please sign in to comment.