Skip to content
Permalink
Browse files

Making Cache::write() trigger warnings when a cache engine returns fa…

…lse from a write. Tests added. Fixes #877
  • Loading branch information...
markstory committed Jul 24, 2010
1 parent 88ea68a commit 43127caad2ae0284ff960b34fe1f858cfd0d962d
Showing with 33 additions and 1 deletion.
  1. +6 −0 cake/libs/cache.php
  2. +22 −0 cake/tests/cases/libs/cache.test.php
  3. +5 −1 cake/tests/test_app/libs/cache/test_app_cache.php
@@ -270,6 +270,12 @@ public static function write($key, $value, $config = null) {
$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;
}
@@ -309,6 +309,28 @@ function testWriteEmptyValues() {
$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
*
@@ -19,7 +19,11 @@
*/
class TestAppCacheEngine extends CacheEngine {
public function write($key, $value, $duration) { }
public function write($key, $value, $duration) {
if ($key = 'fail') {

This comment has been minimized.

Copy link
@hiromi2424

This comment has been minimized.

Copy link
@markstory

markstory Mar 15, 2011

Author Member

You are totally right, fixed in [6fd5ff3]

return false;
}
}
public function read($key) { }

0 comments on commit 43127ca

Please sign in to comment.
You can’t perform that action at this time.