Skip to content

Commit

Permalink
Fixing various errors related to Cache::increment() and Cache::decrem…
Browse files Browse the repository at this point in the history
…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 47c7387
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
8 changes: 4 additions & 4 deletions cake/libs/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 0 additions & 6 deletions cake/libs/cache/memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
15 changes: 7 additions & 8 deletions cake/tests/cases/libs/cache/memcache.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ function testDeleteCache() {
* @access public
* @return void
*/
public function testDecrement() {
function testDecrement() {
$result = Cache::write('test_decrement', 5);
$this->assertTrue($result);

Expand All @@ -242,7 +242,6 @@ public function testDecrement() {

$result = Cache::read('test_decrement');
$this->assertEqual(2, $result);

}

/**
Expand All @@ -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.