Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Cache\Pattern\CallbackCache doesn't work with NULL #4629

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Zend/Cache/Pattern/CallbackCache.php
Expand Up @@ -48,7 +48,7 @@ public function call($callback, array $args = array())
$key = $this->generateCallbackKey($callback, $args);
$result = $storage->getItem($key, $success);
if ($success) {
if (!isset($result[0])) {
if (!array_key_exists(0, $result)) {
throw new Exception\RuntimeException("Invalid cached data for key '{$key}'");
}

Expand Down
21 changes: 21 additions & 0 deletions tests/ZendTest/Cache/Pattern/CallbackCacheTest.php
Expand Up @@ -35,6 +35,14 @@ public static function emptyMethod() {}

}

class FailableCallback
{
public function __invoke()
{
throw new \Exception('This callback should either fail or never be invoked');
}
}

/**
* Test function
* @see ZendTest\Cache\Pattern\Foo::bar
Expand Down Expand Up @@ -165,4 +173,17 @@ protected function _testCall($callback, array $args)
$this->assertEquals('', $data);
}
}

/**
* @group 4629
* @return void
*/
public function testCallCanReturnCachedNullValues()
{
$callback = new FailableCallback();
$key = $this->_pattern->generateKey($callback, array());
$this->_storage->setItem($key, array(null));
$value = $this->_pattern->call($callback);
$this->assertNull($value);
}
}