mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making Cache::write() trigger warnings when a cache engine returns false from a write. Tests added. Fixes #877
This commit is contained in:
parent
88ea68af96
commit
43127caad2
3 changed files with 33 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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) { }
|
||||
|
||||
|
|
Loading…
Reference in a new issue