Skip to content

Commit

Permalink
Make getCache method internal (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus authored Apr 13, 2021
1 parent d8de172 commit c0fbcd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

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

0 comments on commit c0fbcd8

Please sign in to comment.