Making Cache::write() trigger warnings when a cache engine returns false from a write. Tests added. Fixes #877

This commit is contained in:
mark_story 2010-07-23 21:40:57 -04:00
parent 88ea68af96
commit 43127caad2
3 changed files with 33 additions and 1 deletions

View file

@ -270,6 +270,12 @@ class Cache {
$success = self::$_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
self::set();
if ($success === false) {
trigger_error(
sprintf(__("%s cache was unable to write '%s' to cache", true), $config, $key),
E_USER_WARNING
);
}
return $success;
}

View file

@ -309,6 +309,28 @@ class CacheTest extends CakeTestCase {
$this->assertIdentical(Cache::read('App.zeroTest2'), '0');
}
/**
* Test that failed writes cause errors to be triggered.
*
* @return void
*/
function testWriteTriggerError() {
App::build(array(
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
), true);
Cache::config('test_trigger', array('engine' => 'TestAppCache'));
try {
Cache::write('fail', 'value', 'test_trigger');
$this->fail('No exception thrown');
} catch (PHPUnit_Framework_Error $e) {
$this->assertTrue(true);
}
Cache::drop('test_trigger');
App::build();
}
/**
* testCacheDisable method
*

View file

@ -19,7 +19,11 @@
*/
class TestAppCacheEngine extends CacheEngine {
public function write($key, $value, $duration) { }
public function write($key, $value, $duration) {
if ($key = 'fail') {
return false;
}
}
public function read($key) { }