Skip to content
Permalink
Browse files

Fixing various errors related to Cache::increment() and Cache::decrem…

…ent().

Removing php5 only keywords from test cases.
Updating memcache tests, to correctly skip multiple server test when multiple memcached servers cannot be found.
  • Loading branch information...
markstory committed Jan 21, 2010
1 parent e150db2 commit 47c7387548d7a3595ca893c6761e222810899f52
Showing with 11 additions and 18 deletions.
  1. +4 −4 cake/libs/cache.php
  2. +0 −6 cake/libs/cache/memcache.php
  3. +7 −8 cake/tests/cases/libs/cache/memcache.test.php
@@ -353,10 +353,10 @@ function increment($key, $offset = 1, $config = null) {
}
$key = $self->_engines[$config]->key($key);
if (!$key || is_resource($value)) {
if (!$key || !is_integer($offset) || $offset < 0) {
return false;
}
$success = $_this->_Engine[$engine]->increment($settings['prefix'] . $key, $offset);
$success = $self->_engines[$config]->increment($settings['prefix'] . $key, $offset);
$self->set();
return $success;
}
@@ -385,10 +385,10 @@ function decrement($key, $offset = 1, $config = null) {
}
$key = $self->_engines[$config]->key($key);
if (!$key || is_resource($value)) {
if (!$key || !is_integer($offset) || $offset < 0) {
return false;
}
$success = $_this->_Engine[$engine]->increment($settings['prefix'] . $key, $offset);
$success = $self->_engines[$config]->decrement($settings['prefix'] . $key, $offset);
$self->set();
return $success;
}
@@ -138,9 +138,6 @@ function increment($key, $offset = 1) {
if ($this->settings['compress']) {
trigger_error(sprintf(__('Method increment() not implemented for compressed cache in %s', true), get_class($this)), E_USER_ERROR);
}
if (!is_integer($offset) || $offset < 0) {
return false;
}
return $this->__Memcache->increment($key, $offset);
}
@@ -157,9 +154,6 @@ function decrement($key, $offset = 1) {
if ($this->settings['compress']) {
trigger_error(sprintf(__('Method decrement() not implemented for compressed cache in %s', true), get_class($this)), E_USER_ERROR);
}
if (!is_integer($offset) || $offset < 0) {
return false;
}
return $this->__Memcache->decrement($key, $offset);
}
@@ -100,7 +100,7 @@ function testMultipleServers() {
foreach($servers as $server) {
list($host, $port) = explode(':', $server);
if (!$Memcache->addServer($host, $port)) {
if (!@$Memcache->connect($host, $port)) {
$available = false;
}
}
@@ -227,7 +227,7 @@ function testDeleteCache() {
* @access public
* @return void
*/
public function testDecrement() {
function testDecrement() {
$result = Cache::write('test_decrement', 5);
$this->assertTrue($result);
@@ -242,7 +242,6 @@ public function testDecrement() {
$result = Cache::read('test_decrement');
$this->assertEqual(2, $result);
}
/**
@@ -251,21 +250,21 @@ public function testDecrement() {
* @access public
* @return void
*/
public function testIncrement() {
function testIncrement() {
$result = Cache::write('test_increment', 5);
$this->assertTrue($result);
$result = Cache::increment('test_increment');
$this->assertEqual(5, $result);
$this->assertEqual(6, $result);
$result = Cache::read('test_increment');
$this->assertEqual(5, $result);
$this->assertEqual(6, $result);
$result = Cache::increment('test_increment', 2);
$this->assertEqual(7, $result);
$this->assertEqual(8, $result);
$result = Cache::read('test_increment');
$this->assertEqual(7, $result);
$this->assertEqual(8, $result);
}
}
?>

0 comments on commit 47c7387

Please sign in to comment.
You can’t perform that action at this time.