Merge pull request #1061 from dereuromark/2.3-cache-engine

Assert that the cache does not silently fail

Choosing an invalid cache engine should not be a silent error.
This commit is contained in:
Mark Story 2013-01-08 09:23:11 -08:00
commit 0b43a5c05a
2 changed files with 18 additions and 7 deletions

View file

@ -154,20 +154,20 @@ class Cache {
$cacheClass = $class . 'Engine';
App::uses($cacheClass, $plugin . 'Cache/Engine');
if (!class_exists($cacheClass)) {
return false;
throw new CacheException(__d('cake_dev', 'Cache engine %s is not available.', $name));
}
$cacheClass = $class . 'Engine';
if (!is_subclass_of($cacheClass, 'CacheEngine')) {
throw new CacheException(__d('cake_dev', 'Cache engines must use CacheEngine as a base class.'));
}
self::$_engines[$name] = new $cacheClass();
if (self::$_engines[$name]->init($config)) {
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
self::$_engines[$name]->gc();
}
return true;
if (!self::$_engines[$name]->init($config)) {
throw new CacheException(__d('cake_dev', 'Cache engine %s is not properly configured.', $name));
}
return false;
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
self::$_engines[$name]->gc();
}
return true;
}
/**

View file

@ -64,6 +64,17 @@ class CacheTest extends CakeTestCase {
$this->assertTrue(isset($results['settings']));
}
/**
* testConfigInvalidEngine method
*
* @expectedException CacheException
* @return void
*/
public function testConfigInvalidEngine() {
$settings = array('engine' => 'Imaginary');
Cache::config('imaginary', $settings);
}
/**
* Check that no fatal errors are issued doing normal things when Cache.disable is true.
*