Browse Source

Throw exception when selected serializer is not installed

Kamisama 12 years ago
parent
commit
5d509e23c2

+ 8 - 0
lib/Cake/Cache/Engine/MemcachedEngine.php

@@ -143,11 +143,19 @@ class MemcachedEngine extends CacheEngine {
 			case 'igbinary':
 				if (Memcached::HAVE_IGBINARY) {
 					$serializer = self::$serializer['igbinary'];
+				} else {
+					throw new CacheException(
+						__d('cake_dev', 'Memcached extension is not compiled with igbinary support')
+					);
 				}
 				break;
 			case 'json':
 				if (Memcached::HAVE_JSON) {
 					$serializer = self::$serializer['json'];
+				} else {
+					throw new CacheException(
+						__d('cake_dev', 'Memcached extension is not compiled with json support')
+					);
 				}
 				break;
 		}

+ 52 - 2
lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php

@@ -172,7 +172,7 @@ class MemcachedEngineTest extends CakeTestCase {
 	}
 
 /**
- * testPhpSerializerSetting method
+ * testJsonSerializerSetting method
  *
  * @return void
  */
@@ -195,7 +195,7 @@ class MemcachedEngineTest extends CakeTestCase {
 	}
 
 /**
- * testPhpSerializerSetting method
+ * testIgbinarySerializerSetting method
  *
  * @return void
  */
@@ -218,6 +218,56 @@ class MemcachedEngineTest extends CakeTestCase {
 	}
 
 /**
+ * testJsonSerializerThrowException method
+ *
+ * @return void
+ */
+	public function testJsonSerializerThrowException() {
+		$this->skipIf(
+			Memcached::HAVE_JSON,
+			'Memcached extension is compiled with json support'
+		);
+
+		$Memcached = new TestMemcachedEngine();
+		$settings = array(
+			'engine' => 'Memcached',
+			'servers' => array('127.0.0.1:11211'),
+			'persistent' => false,
+			'serializer' => 'json'
+		);
+
+		$this->setExpectedException(
+			'CacheException', 'Memcached extension is not compiled with json support'
+		);
+		$Memcached->init($settings);
+	}
+
+/**
+ * testIgbinarySerializerThrowException method
+ *
+ * @return void
+ */
+	public function testIgbinarySerializerThrowException() {
+		$this->skipIf(
+			Memcached::HAVE_IGBINARY,
+			'Memcached extension is compiled with igbinary support'
+		);
+
+		$Memcached = new TestMemcachedEngine();
+		$settings = array(
+			'engine' => 'Memcached',
+			'servers' => array('127.0.0.1:11211'),
+			'persistent' => false,
+			'serializer' => 'igbinary'
+		);
+
+		$this->setExpectedException(
+			'CacheException', 'Memcached extension is not compiled with igbinary support'
+		);
+		$Memcached->init($settings);
+	}
+
+/**
  * test using authentication without memcached installed with SASL support
  * throw an exception
  *