1
0
mirror of synced 2025-01-09 18:47:10 +03:00

Merge pull request #1177 from c960657/production-settings-arraycache

Ensure metadata cache is not ArrayCache in production
This commit is contained in:
Marco Pivetta 2014-11-11 10:43:29 +01:00
commit 25849a3412
3 changed files with 83 additions and 18 deletions

View File

@ -385,10 +385,16 @@ class Configuration extends \Doctrine\DBAL\Configuration
throw ORMException::queryCacheNotConfigured();
}
if ( ! $this->getMetadataCacheImpl()) {
$metadataCacheImpl = $this->getMetadataCacheImpl();
if ( ! $metadataCacheImpl) {
throw ORMException::metadataCacheNotConfigured();
}
if ($metadataCacheImpl instanceof ArrayCache) {
throw ORMException::metadataCacheUsesNonPersistentCache($metadataCacheImpl);
}
if ($this->getAutoGenerateProxyClasses()) {
throw ORMException::proxyClassesAlwaysRegenerating();
}

View File

@ -19,6 +19,7 @@
namespace Doctrine\ORM;
use Doctrine\Common\Cache\Cache as CacheDriver;
use Exception;
/**
@ -232,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 metadataCacheUsesNonPersistentCache(CacheDriver $cache)
{
return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
}
/**
* @return ORMException
*/

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests\ORM;
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Mapping as AnnotationNamespace;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\ORMException;
@ -136,31 +138,77 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->configuration->getNamedQuery('NonExistingQuery');
}
public function ensureProductionSettings()
/**
* Configures $this->configuration to use production settings.
*
* @param boolean $skipCache Do not configure a cache of this type, either "query" or "metadata".
*/
protected function setProductionSettings($skipCache = false)
{
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER);
$cache = $this->getMock('Doctrine\Common\Cache\Cache');
$this->configuration->setAutoGenerateProxyClasses(true);
try {
$this->configuration->ensureProductionSettings();
$this->fail('Didn\'t check all production settings');
} catch (ORMException $e) {}
if ('query' !== $skipCache) {
$this->configuration->setQueryCacheImpl($cache);
}
$this->configuration->setQueryCacheImpl($cache);
if ('metadata' !== $skipCache) {
$this->configuration->setMetadataCacheImpl($cache);
}
}
try {
$this->configuration->ensureProductionSettings();
$this->fail('Didn\'t check all production settings');
} catch (ORMException $e) {}
public function testEnsureProductionSettings()
{
$this->setProductionSettings();
$this->configuration->ensureProductionSettings();
}
$this->configuration->setMetadataCacheImpl($cache);
public function testEnsureProductionSettingsQueryCache()
{
$this->setProductionSettings('query');
$this->setExpectedException('Doctrine\ORM\ORMException', 'Query Cache is not configured.');
$this->configuration->ensureProductionSettings();
}
try {
$this->configuration->ensureProductionSettings();
$this->fail('Didn\'t check all production settings');
} catch (ORMException $e) {}
public function testEnsureProductionSettingsMetadataCache()
{
$this->setProductionSettings('metadata');
$this->setExpectedException('Doctrine\ORM\ORMException', 'Metadata Cache is not configured.');
$this->configuration->ensureProductionSettings();
}
$this->configuration->setAutoGenerateProxyClasses(false);
public function testEnsureProductionSettingsMetadataArrayCache()
{
$this->setProductionSettings();
$this->configuration->setMetadataCacheImpl(new ArrayCache());
$this->setExpectedException(
'Doctrine\ORM\ORMException',
'Metadata Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.');
$this->configuration->ensureProductionSettings();
}
public function testEnsureProductionSettingsAutoGenerateProxyClassesAlways()
{
$this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_ALWAYS);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings();
}
public function testEnsureProductionSettingsAutoGenerateProxyClassesFileNotExists()
{
$this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings();
}
public function testEnsureProductionSettingsAutoGenerateProxyClassesEval()
{
$this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_EVAL);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings();
}