From c0fbcd8b549fe43cd1e945011e209bf947ccb7a1 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 13 Apr 2021 12:29:47 +0200 Subject: [PATCH] Make getCache method internal (#166) --- .../Mapping/AbstractClassMetadataFactory.php | 4 ++-- .../Mapping/ClassMetadataFactoryTest.php | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php b/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php index 4bd2741e..0242ce0b 100644 --- a/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php +++ b/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php @@ -90,7 +90,7 @@ public function setCacheDriver(?Cache $cacheDriver = null) /** * Gets the cache driver used by the factory to cache ClassMetadata instances. * - * @deprecated getCacheDriver was deprecated in doctrine/persistence 2.2 and will be removed in 3.0. Use getCache instead + * @deprecated getCacheDriver was deprecated in doctrine/persistence 2.2 and will be removed in 3.0. * * @return Cache|null */ @@ -107,7 +107,7 @@ public function setCache(CacheItemPoolInterface $cache): void $this->cacheDriver = new DoctrineProvider($cache); } - public function getCache(): ?CacheItemPoolInterface + final protected function getCache(): ?CacheItemPoolInterface { return $this->cache; } diff --git a/tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php index 2cb60117..560006c3 100644 --- a/tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php @@ -3,12 +3,14 @@ namespace Doctrine\Tests\Persistence\Mapping; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory; use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\Mapping\MappingException; use Doctrine\Tests\DoctrineTestCase; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; +use ReflectionMethod; use stdClass; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\DoctrineAdapter; @@ -32,27 +34,27 @@ protected function setUp(): void public function testSetGetCacheDriver(): void { self::assertNull($this->cmf->getCacheDriver()); - self::assertNull($this->cmf->getCache()); + self::assertNull(self::getCache($this->cmf)); $cache = new ArrayCache(); $this->cmf->setCacheDriver($cache); self::assertSame($cache, $this->cmf->getCacheDriver()); - self::assertInstanceOf(DoctrineAdapter::class, $this->cmf->getCache()); + self::assertInstanceOf(DoctrineAdapter::class, self::getCache($this->cmf)); $this->cmf->setCacheDriver(null); self::assertNull($this->cmf->getCacheDriver()); - self::assertNull($this->cmf->getCache()); + self::assertNull(self::getCache($this->cmf)); } public function testSetGetCache(): void { - self::assertNull($this->cmf->getCache()); + self::assertNull(self::getCache($this->cmf)); self::assertNull($this->cmf->getCacheDriver()); $cache = new ArrayAdapter(); $this->cmf->setCache($cache); - self::assertSame($cache, $this->cmf->getCache()); + self::assertSame($cache, self::getCache($this->cmf)); self::assertInstanceOf(DoctrineProvider::class, $this->cmf->getCacheDriver()); } @@ -236,6 +238,14 @@ public function testWillNotCacheFallbackMetadata(): void self::assertSame($metadata, $this->cmf->getMetadataFor('Foo')); } + + private static function getCache(AbstractClassMetadataFactory $classMetadataFactory): ?CacheItemPoolInterface + { + $method = new ReflectionMethod($classMetadataFactory, 'getCache'); + $method->setAccessible(true); + + return $method->invoke($classMetadataFactory); + } } class RootEntity