Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing test cases and code from merge with 1.3
Making MemcacheEngine::__Memcache protected, so mocking is possible.
  • Loading branch information
markstory committed Jan 19, 2011
1 parent dca3fec commit 23dce83
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 51 deletions.
24 changes: 12 additions & 12 deletions cake/libs/cache/memcache.php
Expand Up @@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine {
* @var Memcache
* @access private
*/
private $__Memcache = null;
protected $_Memcache = null;

/**
* Settings
Expand Down Expand Up @@ -74,12 +74,12 @@ public function init($settings = array()) {
if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->__Memcache)) {
if (!isset($this->_Memcache)) {
$return = false;
$this->__Memcache = new Memcache();
$this->_Memcache = new Memcache();
foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server);
if ($this->__Memcache->addServer($host, $port)) {
if ($this->_Memcache->addServer($host, $port)) {
$return = true;
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public function write($key, $value, $duration) {
if ($duration > 30 * DAY) {
$duration = 0;
}
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration);
}

/**
Expand All @@ -138,7 +138,7 @@ public function write($key, $value, $duration) {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public function read($key) {
return $this->__Memcache->get($key);
return $this->_Memcache->get($key);
}

/**
Expand All @@ -156,7 +156,7 @@ public function increment($key, $offset = 1) {
__('Method increment() not implemented for compressed cache in %s', __CLASS__)
);
}
return $this->__Memcache->increment($key, $offset);
return $this->_Memcache->increment($key, $offset);
}

/**
Expand All @@ -174,7 +174,7 @@ public function decrement($key, $offset = 1) {
__('Method decrement() not implemented for compressed cache in %s', __CLASS__)
);
}
return $this->__Memcache->decrement($key, $offset);
return $this->_Memcache->decrement($key, $offset);
}

/**
Expand All @@ -184,7 +184,7 @@ public function decrement($key, $offset = 1) {
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->__Memcache->delete($key);
return $this->_Memcache->delete($key);
}

/**
Expand All @@ -193,7 +193,7 @@ public function delete($key) {
* @return boolean True if the cache was succesfully cleared, false otherwise
*/
public function clear($check) {
return $this->__Memcache->flush();
return $this->_Memcache->flush();
}

/**
Expand All @@ -204,8 +204,8 @@ public function clear($check) {
* @return boolean True if memcache server was connected
*/
public function connect($host, $port = 11211) {
if ($this->__Memcache->getServerStatus($host, $port) === 0) {
if ($this->__Memcache->connect($host, $port)) {
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
if ($this->_Memcache->connect($host, $port)) {
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/view/view.php
Expand Up @@ -778,8 +778,8 @@ protected function _getElementFileName($name, $plugin = null) {
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
return $path . 'elements' . DS . $name . $this->ext;
if (file_exists($path . 'elements' . DS . $name . $ext)) {
return $path . 'elements' . DS . $name . $ext;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions cake/tests/cases/libs/cache/memcache.test.php
Expand Up @@ -32,13 +32,11 @@ function parseServerString($server) {
return $this->_parseServerString($server);
}

function setMemcache(&$memcache) {
$this->__Memcache = $memcache;
function setMemcache($memcache) {
$this->_Memcache = $memcache;
}
}

Mock::generate('Memcache', 'MemcacheMockMemcache');

/**
* MemcacheEngineTest class
*
Expand Down Expand Up @@ -374,9 +372,11 @@ function testLongDurationEqualToZero() {
$memcache =& new TestMemcacheEngine();
$memcache->settings['compress'] = false;

$mock = new MemcacheMockMemcache();
$mock = $this->getMock('Memcache');
$memcache->setMemcache($mock);
$mock->expectAt(0, 'set', array('key', 'value', false, 0));
$mock->expects($this->once())
->method('set')
->with('key', 'value', false, 0);

$value = 'value';
$memcache->write('key', $value, 50 * DAY);
Expand Down
31 changes: 0 additions & 31 deletions cake/tests/cases/libs/cake_session.test.php
Expand Up @@ -702,35 +702,4 @@ function testSessionTimeout() {
$this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']);
}

/**
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function testDatabaseStorageEmptySessionId() {
unset($_SESSION);
session_destroy();
Configure::write('Session.table', 'sessions');
Configure::write('Session.model', 'Session');
Configure::write('Session.database', 'test_suite');
Configure::write('Session.save', 'database');
$this->setUp();
$id = $this->Session->id();

$this->Session->id = '';
session_id('');

$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');

session_write_close();

unset($_SESSION);
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'php');
session_id($id);
$this->setUp();
}

}
10 changes: 10 additions & 0 deletions cake/tests/cases/libs/session/database_session.test.php
Expand Up @@ -126,6 +126,16 @@ function testWrite() {
$this->assertEquals($expected, $result);
}

/**
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function testWriteEmptySessionId() {
$result = $this->storage->write('', 'This is a Test');
$this->assertFalse($result);
}
/**
* test read()
*
Expand Down

0 comments on commit 23dce83

Please sign in to comment.