From c927478792a482f3fc541c9940d152ddf1f3abc9 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sat, 6 Feb 2016 15:08:19 +0100 Subject: [PATCH] fixed #66 by reducing variable references --- src/Storage/Adapter/Apc.php | 6 +-- src/Storage/Adapter/Memcached.php | 8 ++-- test/Storage/Adapter/CommonAdapterTest.php | 44 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/Storage/Adapter/Apc.php b/src/Storage/Adapter/Apc.php index 4e4e69c8a..195ddba4e 100644 --- a/src/Storage/Adapter/Apc.php +++ b/src/Storage/Adapter/Apc.php @@ -254,7 +254,7 @@ protected function internalGetItems(array & $normalizedKeys) // remove namespace prefix $prefixL = strlen($prefix); $result = []; - foreach ($fetch as $internalKey => & $value) { + foreach ($fetch as $internalKey => $value) { $result[substr($internalKey, $prefixL)] = $value; } @@ -432,9 +432,9 @@ protected function internalSetItems(array & $normalizedKeyValuePairs) $prefix = $namespace . $options->getNamespaceSeparator(); $internalKeyValuePairs = []; - foreach ($normalizedKeyValuePairs as $normalizedKey => &$value) { + foreach ($normalizedKeyValuePairs as $normalizedKey => $value) { $internalKey = $prefix . $normalizedKey; - $internalKeyValuePairs[$internalKey] = &$value; + $internalKeyValuePairs[$internalKey] = $value; } $failedKeys = apc_store($internalKeyValuePairs, null, $options->getTtl()); diff --git a/src/Storage/Adapter/Memcached.php b/src/Storage/Adapter/Memcached.php index ded38c0b8..7aa0f27ad 100644 --- a/src/Storage/Adapter/Memcached.php +++ b/src/Storage/Adapter/Memcached.php @@ -260,8 +260,8 @@ protected function internalGetItems(array & $normalizedKeys) if ($result && $this->namespacePrefix !== '') { $tmp = []; $nsPrefixLength = strlen($this->namespacePrefix); - foreach ($result as $internalKey => & $value) { - $tmp[substr($internalKey, $nsPrefixLength)] = & $value; + foreach ($result as $internalKey => $value) { + $tmp[substr($internalKey, $nsPrefixLength)] = $value; } $result = $tmp; } @@ -399,8 +399,8 @@ protected function internalSetItems(array & $normalizedKeyValuePairs) $expiration = $this->expirationTime(); $namespacedKeyValuePairs = []; - foreach ($normalizedKeyValuePairs as $normalizedKey => & $value) { - $namespacedKeyValuePairs[$this->namespacePrefix . $normalizedKey] = & $value; + foreach ($normalizedKeyValuePairs as $normalizedKey => $value) { + $namespacedKeyValuePairs[$this->namespacePrefix . $normalizedKey] = $value; } if (!$memc->setMulti($namespacedKeyValuePairs, $expiration)) { diff --git a/test/Storage/Adapter/CommonAdapterTest.php b/test/Storage/Adapter/CommonAdapterTest.php index cd2e4beee..3da212e4f 100644 --- a/test/Storage/Adapter/CommonAdapterTest.php +++ b/test/Storage/Adapter/CommonAdapterTest.php @@ -828,6 +828,28 @@ public function testIncrementItemReturnsFalseIfNonWritable() $this->assertEquals(10, $this->_storage->getItem('key')); } + /** + * @link https://github.com/zendframework/zend-cache/issues/66 + */ + public function testSetAndIncrementItems() + { + $this->_storage->setItems([ + 'key1' => 10, + 'key2' => 11, + ]); + + $result = $this->_storage->incrementItems([ + 'key1' => 10, + 'key2' => 20, + ]); + ksort($result); + + $this->assertSame([ + 'key1' => 20, + 'key2' => 31, + ], $result); + } + public function testIncrementItemsResturnsKeyValuePairsOfWrittenItems() { $this->assertTrue($this->_storage->setItem('key1', 10)); @@ -875,6 +897,28 @@ public function testDecrementItemReturnsFalseIfNonWritable() $this->assertEquals(10, $this->_storage->getItem('key')); } + /** + * @link https://github.com/zendframework/zend-cache/issues/66 + */ + public function testSetAndDecrementItems() + { + $this->_storage->setItems([ + 'key1' => 10, + 'key2' => 11, + ]); + + $result = $this->_storage->decrementItems([ + 'key1' => 10, + 'key2' => 5, + ]); + ksort($result); + + $this->assertSame([ + 'key1' => 0, + 'key2' => 6, + ], $result); + } + public function testDecrementItemsReturnsEmptyArrayIfNonWritable() { $this->_storage->setItem('key', 10);