1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Ensure query cache is not ArrayCache in production

This commit is contained in:
Christian Schmidt 2014-12-19 20:18:45 +01:00
parent 193e31f22a
commit 61c72e4aa7
3 changed files with 28 additions and 2 deletions

View File

@ -381,10 +381,16 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function ensureProductionSettings()
{
if ( ! $this->getQueryCacheImpl()) {
$queryCacheImpl = $this->getQueryCacheImpl();
if ( ! $queryCacheImpl) {
throw ORMException::queryCacheNotConfigured();
}
if ($queryCacheImpl instanceof ArrayCache) {
throw ORMException::queryCacheUsesNonPersistentCache($queryCacheImpl);
}
$metadataCacheImpl = $this->getMetadataCacheImpl();
if ( ! $metadataCacheImpl) {

View File

@ -233,6 +233,16 @@ class ORMException extends Exception
return new self('Class Metadata Cache is not configured.');
}
/**
* @param \Doctrine\Common\Cache\Cache $cache
*
* @return ORMException
*/
public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
{
return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
}
/**
* @param \Doctrine\Common\Cache\Cache $cache
*

View File

@ -147,7 +147,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
/**
* Configures $this->configuration to use production settings.
*
* @param boolean $skipCache Do not configure a cache of this type, either "query" or "metadata".
* @param string $skipCache Do not configure a cache of this type, either "query" or "metadata".
*/
protected function setProductionSettings($skipCache = false)
{
@ -184,6 +184,16 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->configuration->ensureProductionSettings();
}
public function testEnsureProductionSettingsQueryArrayCache()
{
$this->setProductionSettings();
$this->configuration->setQueryCacheImpl(new ArrayCache());
$this->setExpectedException(
'Doctrine\ORM\ORMException',
'Query Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.');
$this->configuration->ensureProductionSettings();
}
public function testEnsureProductionSettingsMetadataArrayCache()
{
$this->setProductionSettings();