Skip to content

Commit

Permalink
Adding exception tossing for invalid cacheengine configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 24, 2010
1 parent 6f0b43f commit 0fc1064
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cake/libs/cache.php
Expand Up @@ -126,6 +126,9 @@ protected static function _buildEngine($name) {
}
$cacheClass = $class . 'Engine';
self::$_engines[$name] = new $cacheClass();
if (!self::$_engines[$name] instanceof CacheEngine) {
throw new Exception(__('Cache engines must use CacheEngine as a base class.'));
}
if (self::$_engines[$name]->init($config)) {
if (time() % self::$_engines[$name]->settings['probability'] === 0) {
self::$_engines[$name]->gc();
Expand Down
14 changes: 14 additions & 0 deletions cake/tests/cases/libs/cache.test.php
Expand Up @@ -21,6 +21,8 @@
require LIBS . 'cache.php';
}

Mock::generate('StdClass', 'RubbishEngine');

/**
* CacheTest class
*
Expand Down Expand Up @@ -131,6 +133,18 @@ function testInvaidConfig() {
$this->assertEqual($read, null);
}

/**
* test that trying to configure classes that don't extend CacheEngine fail.
*
* @return void
*/
function testAttemptingToConfigureANonCacheEngineClass() {
$this->expectException();
Cache::config('Garbage', array(
'engine' => 'Rubbish'
));
}

/**
* testConfigChange method
*
Expand Down

0 comments on commit 0fc1064

Please sign in to comment.