Skip to content

Commit

Permalink
Updating memcache test to use new Cache api.
Browse files Browse the repository at this point in the history
Removing most private access in the test case.
  • Loading branch information
markstory committed Nov 21, 2009
1 parent 266cddb commit 5ff2e66
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions cake/tests/cases/libs/cache/memcache.test.php
Expand Up @@ -2,8 +2,6 @@
/**
* MemcacheEngineTest file
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
Expand All @@ -23,13 +21,6 @@
require LIBS . 'cache.php';
}

/**
* MemcacheEngineTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.cache
*/

/**
* MemcacheEngineTest class
*
Expand All @@ -46,7 +37,7 @@ class MemcacheEngineTest extends CakeTestCase {
*/
function skip() {
$skip = true;
if (Cache::engine('Memcache')) {
if (class_exists('Memcache')) {
$skip = false;
}
$this->skipIf($skip, '%s Memcache is not installed or configured properly');
Expand All @@ -72,6 +63,7 @@ function setUp() {
*/
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::drop('memcache');
Cache::config('default');
}

Expand Down Expand Up @@ -103,28 +95,26 @@ function testSettings() {
*/
function testMultipleServers() {
$servers = array('127.0.0.1:11211', '127.0.0.1:11222');

$Cache =& Cache::getInstance();
$MemCache =& $Cache->_Engine['Memcache'];

$available = true;
$Memcache =& new Memcache();

foreach($servers as $server) {
list($host, $port) = explode(':', $server);
if (!@$MemCache->__Memcache->connect($host, $port)) {
if (!$Memcache->addServer($host, $port)) {
$available = false;
}
}

if ($this->skipIf(!$available, '%s Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
return;
}
$Memcache =& new MemcacheEngine();
$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));

unset($MemCache->__Memcache);
$MemCache->init(array('engine' => 'Memcache', 'servers' => $servers));

$servers = array_keys($MemCache->__Memcache->getExtendedStats());
$settings = Cache::settings();
$servers = array_keys($Memcache->__Memcache->getExtendedStats());
$settings = $Memcache->settings();
$this->assertEqual($servers, $settings['servers']);
Cache::drop('dual_server');
}

/**
Expand All @@ -134,8 +124,9 @@ function testMultipleServers() {
* @return void
*/
function testConnect() {
$Cache =& Cache::getInstance();
$result = $Cache->_Engine['Memcache']->connect('127.0.0.1');
$Memcache =& new MemcacheEngine();
$Memcache->init(Cache::settings('memcache'));
$result = $Memcache->connect('127.0.0.1');
$this->assertTrue($result);
}

Expand Down Expand Up @@ -193,13 +184,13 @@ function testExpiry() {
$result = Cache::read('other_test');
$this->assertFalse($result);

Cache::engine('Memcache', array('duration' => '+1 second'));
Cache::config('memcache', array('duration' => '+1 second'));
sleep(2);

$result = Cache::read('other_test');
$this->assertFalse($result);

Cache::engine('Memcache', array('duration' => '+31 day'));
Cache::config('memcache', array('duration' => '+31 day'));
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('long_expiry_test', $data);
$this->assertTrue($result);
Expand All @@ -212,7 +203,7 @@ function testExpiry() {
$result = Cache::read('long_expiry_test');
$this->assertTrue($result);

Cache::engine('Memcache', array('duration' => 3600));
Cache::config('memcache', array('duration' => 3600));
}

/**
Expand Down

0 comments on commit 5ff2e66

Please sign in to comment.