mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing test cases and code from merge with 1.3
Making MemcacheEngine::__Memcache protected, so mocking is possible.
This commit is contained in:
parent
dca3fecfed
commit
23dce83836
5 changed files with 30 additions and 51 deletions
24
cake/libs/cache/memcache.php
vendored
24
cake/libs/cache/memcache.php
vendored
|
@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @var Memcache
|
||||
* @access private
|
||||
*/
|
||||
private $__Memcache = null;
|
||||
protected $_Memcache = null;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
|
@ -74,12 +74,12 @@ class MemcacheEngine extends CacheEngine {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
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__)
|
||||
);
|
||||
}
|
||||
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__)
|
||||
);
|
||||
}
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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;
|
||||
|
|
|
@ -778,8 +778,8 @@ class View extends Object {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
cake/tests/cases/libs/cache/memcache.test.php
vendored
12
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -32,13 +32,11 @@ class TestMemcacheEngine extends MemcacheEngine {
|
|||
return $this->_parseServerString($server);
|
||||
}
|
||||
|
||||
function setMemcache(&$memcache) {
|
||||
$this->__Memcache = $memcache;
|
||||
function setMemcache($memcache) {
|
||||
$this->_Memcache = $memcache;
|
||||
}
|
||||
}
|
||||
|
||||
Mock::generate('Memcache', 'MemcacheMockMemcache');
|
||||
|
||||
/**
|
||||
* MemcacheEngineTest class
|
||||
*
|
||||
|
@ -374,9 +372,11 @@ class MemcacheEngineTest extends CakeTestCase {
|
|||
$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);
|
||||
|
|
|
@ -702,35 +702,4 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -126,6 +126,16 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
$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()
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue