Browse Source

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.
mark_story 14 years ago
parent
commit
7f68699fcd
2 changed files with 17 additions and 4 deletions
  1. 4 4
      lib/Cake/Cache/Cache.php
  2. 13 0
      lib/Cake/Test/Case/Cache/CacheTest.php

+ 4 - 4
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;

+ 13 - 0
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.
  *