Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline cache creation in tests #9451

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions tests/Doctrine/Tests/OrmFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests;

use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
Expand Down Expand Up @@ -61,9 +60,9 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
/**
* The metadata cache shared between all functional tests.
*
* @var Cache|CacheItemPoolInterface|null
* @var CacheItemPoolInterface|null
*/
private static $_metadataCache = null;
private static $metadataCache = null;

/**
* The query cache shared between all functional tests.
Expand Down Expand Up @@ -711,12 +710,8 @@ protected function getEntityManager(
// NOTE: Functional tests use their own shared metadata cache, because
// the actual database platform used during execution has effect on some
// metadata mapping behaviors (like the choice of the ID generation).
if (self::$_metadataCache === null) {
if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) {
self::$_metadataCache = new $GLOBALS['DOCTRINE_CACHE_IMPL']();
} else {
self::$_metadataCache = new ArrayAdapter();
}
if (self::$metadataCache === null) {
self::$metadataCache = new ArrayAdapter();
}

if (self::$queryCache === null) {
Expand All @@ -726,12 +721,7 @@ protected function getEntityManager(
//FIXME: two different configs! $conn and the created entity manager have
// different configs.
$config = new Configuration();
if (self::$_metadataCache instanceof CacheItemPoolInterface) {
$config->setMetadataCache(self::$_metadataCache);
} else {
$config->setMetadataCacheImpl(self::$_metadataCache);
}

$config->setMetadataCache(self::$metadataCache);
$config->setQueryCache(self::$queryCache);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
Expand Down
22 changes: 8 additions & 14 deletions tests/Doctrine/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class OrmTestCase extends DoctrineTestCase
*
* @var CacheItemPoolInterface|null
*/
private static $_metadataCache = null;
private static $metadataCache = null;

/**
* The query cache that is shared between all ORM tests (except functional tests).
Expand All @@ -54,7 +54,7 @@ abstract class OrmTestCase extends DoctrineTestCase
protected $secondLevelCacheLogger;

/** @var CacheItemPoolInterface|null */
protected $secondLevelCache = null;
private $secondLevelCache = null;

protected function createAnnotationDriver(array $paths = []): AnnotationDriver
{
Expand Down Expand Up @@ -125,28 +125,22 @@ protected function getTestEntityManager(
return EntityManagerMock::create($conn, $config, $eventManager);
}

protected function enableSecondLevelCache($log = true): void
protected function enableSecondLevelCache(bool $log = true): void
{
$this->isSecondLevelCacheEnabled = true;
$this->isSecondLevelCacheLogEnabled = $log;
}

private static function getSharedMetadataCacheImpl(): ?CacheItemPoolInterface
private static function getSharedMetadataCacheImpl(): CacheItemPoolInterface
{
if (self::$_metadataCache === null) {
self::$_metadataCache = new ArrayAdapter();
}

return self::$_metadataCache;
return self::$metadataCache
?? self::$metadataCache = new ArrayAdapter();
}

private static function getSharedQueryCache(): CacheItemPoolInterface
{
if (self::$queryCache === null) {
self::$queryCache = new ArrayAdapter();
}

return self::$queryCache;
return self::$queryCache
?? self::$queryCache = new ArrayAdapter();
}

protected function getSharedSecondLevelCache(): CacheItemPoolInterface
Expand Down