Fix return values in Cache.

The documentation indicates that false/or the value will be returnned.
Using both null and false to indicate failure is confusing.  Use only
false to indicate failure.  It might be better in the future to use
exceptions for trying to read/write on missing cache configs.
This commit is contained in:
mark_story 2011-11-29 23:17:17 -05:00
parent 992a1554e1
commit 7f68699fcd
2 changed files with 17 additions and 4 deletions

View file

@ -285,7 +285,7 @@ class Cache {
$settings = self::settings($config);
if (empty($settings)) {
return null;
return false;
}
if (!self::isInitialized($config)) {
return false;
@ -335,7 +335,7 @@ class Cache {
$settings = self::settings($config);
if (empty($settings)) {
return null;
return false;
}
if (!self::isInitialized($config)) {
return false;
@ -360,7 +360,7 @@ class Cache {
$settings = self::settings($config);
if (empty($settings)) {
return null;
return false;
}
if (!self::isInitialized($config)) {
return false;
@ -422,7 +422,7 @@ class Cache {
$settings = self::settings($config);
if (empty($settings)) {
return null;
return false;
}
if (!self::isInitialized($config)) {
return false;

View file

@ -126,6 +126,19 @@ class CacheTest extends CakeTestCase {
$read = Cache::read('Test', 'invalid');
}
/**
* Test reading from a config that is undefined.
*
* @return void
*/
public function testReadNonExistingConfig() {
$this->assertFalse(Cache::read('key', 'totally fake'));
$this->assertFalse(Cache::write('key', 'value', 'totally fake'));
$this->assertFalse(Cache::increment('key', 'value', 'totally fake'));
$this->assertFalse(Cache::decrement('key', 'value', 'totally fake'));
}
/**
* test that trying to configure classes that don't extend CacheEngine fail.
*