From 61c72e4aa7d172bef85ebea92aa055f25538f3b0 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 19 Dec 2014 20:18:45 +0100 Subject: [PATCH] Ensure query cache is not ArrayCache in production --- lib/Doctrine/ORM/Configuration.php | 8 +++++++- lib/Doctrine/ORM/ORMException.php | 10 ++++++++++ tests/Doctrine/Tests/ORM/ConfigurationTest.php | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index aaba37177..04817760d 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -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) { diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 2b4552932..96e342eb2 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -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 * diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index 1682b6dbb..cb9ec66be 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -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();