diff --git a/cake/libs/cache.php b/cake/libs/cache.php index 04d6d78fcd1..324e9fb4c86 100644 --- a/cake/libs/cache.php +++ b/cake/libs/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; } diff --git a/cake/tests/cases/libs/cache.test.php b/cake/tests/cases/libs/cache.test.php index 58529ba3bca..964e3a2fc50 100644 --- a/cake/tests/cases/libs/cache.test.php +++ b/cake/tests/cases/libs/cache.test.php @@ -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 * diff --git a/cake/tests/test_app/libs/cache/test_app_cache.php b/cake/tests/test_app/libs/cache/test_app_cache.php index 548a3e56d09..9e4a14b4597 100644 --- a/cake/tests/test_app/libs/cache/test_app_cache.php +++ b/cake/tests/test_app/libs/cache/test_app_cache.php @@ -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) { }