Skip to content

Commit

Permalink
Throw exception when selected serializer is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Sep 18, 2013
1 parent bd3f005 commit 5d509e2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/Cake/Cache/Engine/MemcachedEngine.php
Expand Up @@ -143,11 +143,19 @@ protected function _setOptions() {
case 'igbinary': case 'igbinary':
if (Memcached::HAVE_IGBINARY) { if (Memcached::HAVE_IGBINARY) {
$serializer = self::$serializer['igbinary']; $serializer = self::$serializer['igbinary'];
} else {
throw new CacheException(
__d('cake_dev', 'Memcached extension is not compiled with igbinary support')
);
} }
break; break;
case 'json': case 'json':
if (Memcached::HAVE_JSON) { if (Memcached::HAVE_JSON) {
$serializer = self::$serializer['json']; $serializer = self::$serializer['json'];
} else {
throw new CacheException(
__d('cake_dev', 'Memcached extension is not compiled with json support')
);
} }
break; break;
} }
Expand Down
54 changes: 52 additions & 2 deletions lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -172,7 +172,7 @@ public function testPhpSerializerSetting() {
} }


/** /**
* testPhpSerializerSetting method * testJsonSerializerSetting method
* *
* @return void * @return void
*/ */
Expand All @@ -195,7 +195,7 @@ public function testJsonSerializerSetting() {
} }


/** /**
* testPhpSerializerSetting method * testIgbinarySerializerSetting method
* *
* @return void * @return void
*/ */
Expand All @@ -217,6 +217,56 @@ public function testIgbinarySerializerSetting() {
$this->assertEquals(Memcached::SERIALIZER_IGBINARY, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER)); $this->assertEquals(Memcached::SERIALIZER_IGBINARY, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER));
} }


/**
* 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 * test using authentication without memcached installed with SASL support
* throw an exception * throw an exception
Expand Down

0 comments on commit 5d509e2

Please sign in to comment.