Fixing test cases and code from merge with 1.3

Making MemcacheEngine::__Memcache protected, so mocking is possible.
This commit is contained in:
mark_story 2011-01-18 20:20:49 -05:00
parent dca3fecfed
commit 23dce83836
5 changed files with 30 additions and 51 deletions

View file

@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine {
* @var Memcache * @var Memcache
* @access private * @access private
*/ */
private $__Memcache = null; protected $_Memcache = null;
/** /**
* Settings * Settings
@ -74,12 +74,12 @@ class MemcacheEngine extends CacheEngine {
if (!is_array($this->settings['servers'])) { if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']); $this->settings['servers'] = array($this->settings['servers']);
} }
if (!isset($this->__Memcache)) { if (!isset($this->_Memcache)) {
$return = false; $return = false;
$this->__Memcache = new Memcache(); $this->_Memcache = new Memcache();
foreach ($this->settings['servers'] as $server) { foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server); list($host, $port) = $this->_parseServerString($server);
if ($this->__Memcache->addServer($host, $port)) { if ($this->_Memcache->addServer($host, $port)) {
$return = true; $return = true;
} }
} }
@ -128,7 +128,7 @@ class MemcacheEngine extends CacheEngine {
if ($duration > 30 * DAY) { if ($duration > 30 * DAY) {
$duration = 0; $duration = 0;
} }
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration); return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration);
} }
/** /**
@ -138,7 +138,7 @@ class MemcacheEngine extends CacheEngine {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it * @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) { public function read($key) {
return $this->__Memcache->get($key); return $this->_Memcache->get($key);
} }
/** /**
@ -156,7 +156,7 @@ class MemcacheEngine extends CacheEngine {
__('Method increment() not implemented for compressed cache in %s', __CLASS__) __('Method increment() not implemented for compressed cache in %s', __CLASS__)
); );
} }
return $this->__Memcache->increment($key, $offset); return $this->_Memcache->increment($key, $offset);
} }
/** /**
@ -174,7 +174,7 @@ class MemcacheEngine extends CacheEngine {
__('Method decrement() not implemented for compressed cache in %s', __CLASS__) __('Method decrement() not implemented for compressed cache in %s', __CLASS__)
); );
} }
return $this->__Memcache->decrement($key, $offset); return $this->_Memcache->decrement($key, $offset);
} }
/** /**
@ -184,7 +184,7 @@ class MemcacheEngine extends CacheEngine {
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
*/ */
public function delete($key) { public function delete($key) {
return $this->__Memcache->delete($key); return $this->_Memcache->delete($key);
} }
/** /**
@ -193,7 +193,7 @@ class MemcacheEngine extends CacheEngine {
* @return boolean True if the cache was succesfully cleared, false otherwise * @return boolean True if the cache was succesfully cleared, false otherwise
*/ */
public function clear($check) { public function clear($check) {
return $this->__Memcache->flush(); return $this->_Memcache->flush();
} }
/** /**
@ -204,8 +204,8 @@ class MemcacheEngine extends CacheEngine {
* @return boolean True if memcache server was connected * @return boolean True if memcache server was connected
*/ */
public function connect($host, $port = 11211) { public function connect($host, $port = 11211) {
if ($this->__Memcache->getServerStatus($host, $port) === 0) { if ($this->_Memcache->getServerStatus($host, $port) === 0) {
if ($this->__Memcache->connect($host, $port)) { if ($this->_Memcache->connect($host, $port)) {
return true; return true;
} }
return false; return false;

View file

@ -778,8 +778,8 @@ class View extends Object {
$exts = $this->_getExtensions(); $exts = $this->_getExtensions();
foreach ($exts as $ext) { foreach ($exts as $ext) {
foreach ($paths as $path) { foreach ($paths as $path) {
if (file_exists($path . 'elements' . DS . $name . $this->ext)) { if (file_exists($path . 'elements' . DS . $name . $ext)) {
return $path . 'elements' . DS . $name . $this->ext; return $path . 'elements' . DS . $name . $ext;
} }
} }
} }

View file

@ -32,13 +32,11 @@ class TestMemcacheEngine extends MemcacheEngine {
return $this->_parseServerString($server); return $this->_parseServerString($server);
} }
function setMemcache(&$memcache) { function setMemcache($memcache) {
$this->__Memcache = $memcache; $this->_Memcache = $memcache;
} }
} }
Mock::generate('Memcache', 'MemcacheMockMemcache');
/** /**
* MemcacheEngineTest class * MemcacheEngineTest class
* *
@ -374,9 +372,11 @@ class MemcacheEngineTest extends CakeTestCase {
$memcache =& new TestMemcacheEngine(); $memcache =& new TestMemcacheEngine();
$memcache->settings['compress'] = false; $memcache->settings['compress'] = false;
$mock = new MemcacheMockMemcache(); $mock = $this->getMock('Memcache');
$memcache->setMemcache($mock); $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'; $value = 'value';
$memcache->write('key', $value, 50 * DAY); $memcache->write('key', $value, 50 * DAY);

View file

@ -702,35 +702,4 @@ class CakeSessionTest extends CakeTestCase {
$this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']); $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();
}
} }

View file

@ -126,6 +126,16 @@ class DatabaseSessionTest extends CakeTestCase {
$this->assertEquals($expected, $result); $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() * test read()
* *