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

fixed #66 by reducing variables by reference #67

Merged
merged 1 commit into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down
44 changes: 44 additions & 0 deletions test/Storage/Adapter/CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down