diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index d9ebe757a..b6d9cc640 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -72,6 +72,7 @@ class MemcacheEngine extends CacheEngine { $this->settings['servers'] = array($this->settings['servers']); } if (!isset($this->__Memcache)) { + $return = false; $this->__Memcache =& new Memcache(); foreach ($this->settings['servers'] as $server) { $parts = explode(':', $server); @@ -81,10 +82,10 @@ class MemcacheEngine extends CacheEngine { $port = $parts[1]; } if ($this->__Memcache->addServer($host, $port)) { - return true; + $return = true; } } - return false; + return $return; } return true; } @@ -154,4 +155,4 @@ class MemcacheEngine extends CacheEngine { return true; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 66451cca5..602e1b417 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -38,7 +38,7 @@ if (!class_exists('Cache')) { * @package cake * @subpackage cake.tests.cases.libs.cache */ -class MemcacheEngineTest extends UnitTestCase { +class MemcacheEngineTest extends CakeTestCase { /** * skip method * @@ -47,10 +47,10 @@ class MemcacheEngineTest extends UnitTestCase { */ function skip() { $skip = true; - if ($result = Cache::engine('Memcache')) { + if (Cache::engine('Memcache')) { $skip = false; } - $this->skipif($skip, 'Memcache is not installed or configured properly'); + $this->skipIf($skip, 'Memcache is not installed or configured properly'); } /** * setUp method @@ -61,6 +61,15 @@ class MemcacheEngineTest extends UnitTestCase { function setUp() { Cache::config('memcache', array('engine'=>'Memcache', 'prefix' => 'cake_')); } +/** + * tearDown method + * + * @access public + * @return void + */ + function tearDown() { + Cache::config('default'); + } /** * testSettings method * @@ -78,6 +87,37 @@ class MemcacheEngineTest extends UnitTestCase { ); $this->assertEqual($settings, $expecting); } +/** + * testSettings method + * + * @access public + * @return void + */ + function testMultipleServers() { + $servers = array('127.0.0.1:11211', '127.0.0.1:11222'); + + $Cache =& Cache::getInstance(); + $MemCache =& $Cache->_Engine['Memcache']; + + $available = true; + foreach($servers as $server) { + list($host, $port) = explode(':', $server); + if (!@$MemCache->__Memcache->connect($host, $port)) { + $available = false; + } + } + + if ($this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) { + return; + } + + unset($MemCache->__Memcache); + $MemCache->init(array('engine' => 'Memcache', 'servers' => $servers)); + + $servers = array_keys($MemCache->__Memcache->getExtendedStats()); + $settings = Cache::settings(); + $this->assertEqual($servers, $settings['servers']); + } /** * testConnect method * @@ -165,14 +205,5 @@ class MemcacheEngineTest extends UnitTestCase { $result = Cache::delete('delete_test'); $this->assertTrue($result); } -/** - * tearDown method - * - * @access public - * @return void - */ - function tearDown() { - Cache::config('default'); - } } -?> \ No newline at end of file +?>