mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
commit
0b43a5c05a
2 changed files with 18 additions and 7 deletions
|
@ -154,21 +154,21 @@ 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]->init($config)) {
|
||||
throw new CacheException(__d('cake_dev', 'Cache engine %s is not properly configured.', $name));
|
||||
}
|
||||
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
|
||||
self::$_engines[$name]->gc();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the currently configured Cache settings.
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue