From 7f68699fcdb2ed3461f4fe1408eada1695df64ca Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 29 Nov 2011 23:17:17 -0500 Subject: [PATCH] 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. --- lib/Cake/Cache/Cache.php | 8 ++++---- lib/Cake/Test/Case/Cache/CacheTest.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Cache/Cache.php b/lib/Cake/Cache/Cache.php index e80ca5b02..3b933ebac 100644 --- a/lib/Cake/Cache/Cache.php +++ b/lib/Cake/Cache/Cache.php @@ -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; diff --git a/lib/Cake/Test/Case/Cache/CacheTest.php b/lib/Cake/Test/Case/Cache/CacheTest.php index 2bc3f8a9d..f526a2cfb 100644 --- a/lib/Cake/Test/Case/Cache/CacheTest.php +++ b/lib/Cake/Test/Case/Cache/CacheTest.php @@ -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. *