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

Commit

Permalink
Merge branch 'hotfix/object-cache' of https://github.com/SocalNick/zf2
Browse files Browse the repository at this point in the history
…into hotfix/cache-entity
  • Loading branch information
weierophinney committed Feb 1, 2012
4 parents 9a8e72f + a75171a + 814716e + 613a0f6 commit 1f29b3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Pattern/ObjectCache.php
Expand Up @@ -184,7 +184,7 @@ public function call($method, array $args = array(), array $options = array())

if (!isset($options['callback_key'])) {
if ((isset($options['entity_key']) && ($entityKey = $options['entity_key']) !== null)
|| ($entityKey = $classOptions->getObjectKey() !== null)
|| (($entityKey = $classOptions->getObjectKey()) !== null)
) {
$options['callback_key'] = $entityKey . '::' . strtolower($method);
unset($options['entity_key']);
Expand All @@ -208,7 +208,7 @@ public function generateKey($method, array $args = array(), array $options = arr
$classOptions = $this->getOptions();
if (!isset($options['callback_key'])) {
if ( (isset($options['entity_key']) && ($entityKey = $options['entity_key']) !== null)
|| ($entityKey = $classOptions->getObjectKey() !== null)) {
|| (($entityKey = $classOptions->getObjectKey()) !== null)) {
$options['callback_key'] = $entityKey . '::' . strtolower($method);
unset($options['entity_key']);
}
Expand Down
39 changes: 39 additions & 0 deletions test/Pattern/ObjectCacheTest.php
Expand Up @@ -158,6 +158,45 @@ public function testGenerateKeyWithPredefinedEntityKey()
);
}

public function testGenerateKeyWithClassObjectKey()
{
$args = array('arg1', 2, 3.33, null);
$key = $this->_pattern->generateKey('emptyMethod', $args, array('callback_key' => 'test-object-cache::emptymethod'));

$class = __NAMESPACE__ . '\TestObjectCache';
$options = new Cache\Pattern\PatternOptions(array(
'object' => new $class(),
'storage' => $this->_storage,
'objectKey' => 'test-object-cache',
));
$this->_pattern->setOptions($options);

$keyWithClassObjectKey = $this->_pattern->generateKey('emptyMethod', $args);
$this->assertEquals($key, $keyWithClassObjectKey);
}

public function testCallWithClassObjectKey()
{
$class = __NAMESPACE__ . '\TestObjectCache';
$options = new Cache\Pattern\PatternOptions(array(
'object' => new $class(),
'storage' => $this->_storage,
'objectKey' => 'test-object-cache',
));
$this->_pattern->setOptions($options);

$args = array('arg1', 2, 3.33, null);

$usedCallbackKey = null;
$this->_options->getStorage()->events()->attach('setItem.pre', function ($event) use (&$usedCallbackKey) {
$params = $event->getParams();
$usedCallbackKey = $params['options']['callback_key'];
});

$this->_pattern->call('emptyMethod', $args);
$this->assertEquals('test-object-cache::emptymethod', $usedCallbackKey);
}

public function testCallUnknownMethodException()
{
$this->setExpectedException('Zend\Cache\Exception\InvalidArgumentException');
Expand Down

0 comments on commit 1f29b3e

Please sign in to comment.