From afd02aaf2ce49ff5a0890179695fc3eab08fdce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20B=C3=A1lint?= Date: Thu, 13 Jun 2024 10:14:42 +0200 Subject: [PATCH] test: Write a test for prefixed cache key support --- .../AbstractClassMetadataFactoryTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php b/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php index d8f43eb5..ad30105c 100644 --- a/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php +++ b/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php @@ -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; @@ -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