Skip to content

Commit

Permalink
test: Write a test for prefixed cache key support
Browse files Browse the repository at this point in the history
  • Loading branch information
adambalint-srg committed Jun 13, 2024
1 parent 46d44c5 commit afd02aa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\MappingException;
use Doctrine\Tests\DoctrineTestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;

use function get_class;

Expand Down Expand Up @@ -92,6 +94,31 @@ public function testItGetsTheSameMetadataForBackslashedClassName(): void
/** @psalm-suppress ArgumentTypeCoercion */
self::assertSame($cmf->getMetadataFor(SomeOtherEntity::class), $cmf->getMetadataFor('\\' . SomeOtherEntity::class));
}

public function testCacheStoredWithPrefixedKeys(): void
{
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
$cmf
->method('newClassMetadataInstance')
->with(SomeOtherEntity::class)
->willReturn(
$this->createStub(ClassMetadata::class)
);

$cache = $this->createMock(CacheItemPoolInterface::class);
$cmf->setCache($cache);

$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('getKey')->willReturn('prefix__Doctrine__Tests__Persistence__Mapping__SomeOtherEntity__CLASSMETADATA__'); //Cache item's key is prefixed
$cache->method('getItems')
->with(['Doctrine__Tests__Persistence__Mapping__SomeOtherEntity__CLASSMETADATA__']) //Key which is generated from class name is not prefixed
->willReturn([$cacheItem]);

$cacheItem->expects(self::once())->method('set');
$cache->expects(self::once())->method('saveDeferred');

$cmf->getMetadataFor(SomeOtherEntity::class);
}
}

class SomeGrandParentEntity
Expand Down

0 comments on commit afd02aa

Please sign in to comment.