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

Commit

Permalink
Merge branch 'cache-get-item-fix' of github.com:hver/zf2 into hver-ca…
Browse files Browse the repository at this point in the history
…che-get-item-fix
  • Loading branch information
mwillbanks committed Aug 27, 2014
2 parents 766fd11 + f88b774 commit 2a9c590
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/Zend/Cache/Storage/Adapter/AbstractAdapter.php
Expand Up @@ -370,7 +370,8 @@ public function getItem($key, & $success = null, & $casToken = null)
}
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
$result = null;
$success = false;
return $this->triggerException(__FUNCTION__, $args, $result, $e);
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/ZendTest/Cache/Storage/Adapter/AbstractAdapterTest.php
Expand Up @@ -356,6 +356,32 @@ public function testGetMetadataCallsInternalGetMetadata()
$this->assertSame($result, $rs);
}

public function testGetItemReturnsNullIfFailed()
{
$this->_storage = $this->getMockForAbstractAdapter(array('internalGetItem'));

$key = 'key1';

// Do not throw exceptions outside the adapter
$pluginOptions = new Cache\Storage\Plugin\PluginOptions(
array('throw_exceptions' => false)
);
$plugin = new Cache\Storage\Plugin\ExceptionHandler();
$plugin->setOptions($pluginOptions);
$this->_storage->addPlugin($plugin);

// Simulate internalGetItem() throwing an exception
$this->_storage
->expects($this->once())
->method('internalGetItem')
->with($this->equalTo($key))
->will($this->throwException(new \Exception('internalGet failed')));

$result = $this->_storage->getItem($key, $success);
$this->assertNull($result, 'GetItem should return null the item cannot be retrieved');
$this->assertFalse($success, '$success should be false if the item cannot be retrieved');
}

/*
public function testGetMetadatas()
{
Expand Down

0 comments on commit 2a9c590

Please sign in to comment.