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

Merge pull request #1227 from c960657/production-settings-query-cache

Ensure query cache is not ArrayCache in production
This commit is contained in:
Marco Pivetta 2015-01-09 16:58:38 +01:00
commit 664b6bf4c5
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();