Skip to content

Commit

Permalink
Merge remote-tracking branch 'phpsocialnetwork/v6' into v6
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Sep 15, 2019
2 parents 1962706 + 93098b0 commit 1dcdc4c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/phpFastCache/Helper/Psr16Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function clear()
*/
public function getMultiple($keys, $default = null)
{
if ($keys instanceof \Traversable) {
$keys = \iterator_to_array($keys);
}
try {
return array_map(function (ExtendedCacheItemInterface $item) {
return $item->get();
Expand Down Expand Up @@ -167,7 +170,13 @@ public function setMultiple($values, $ttl = null)
public function deleteMultiple($keys)
{
try {
return $this->internalCacheInstance->deleteItems($keys);
if ($keys instanceof \Traversable) {
return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
} elseif (is_array($keys)) {
return $this->internalCacheInstance->deleteItems($keys);
} else {
throw new phpFastCacheInvalidArgumentException('$keys must be an array/Traversable instance.');
}
} catch (phpFastCacheInvalidArgumentException $e) {
throw new phpFastCacheSimpleCacheException($e->getMessage(), null, $e);
}
Expand Down
68 changes: 55 additions & 13 deletions tests/Psr16Adapter.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
$value = str_shuffle(uniqid('pfc', true));

if(!$Psr16Adapter->has('test-key')){
$testHelper->printPassText('1/6 Psr16 hasser returned expected boolean (false)');
$testHelper->printPassText('1/9 Psr16 hasser returned expected boolean (false)');
}else{
$testHelper->printFailText('1/6 Psr16 hasser returned unexpected boolean (true)');
$testHelper->printFailText('1/9 Psr16 hasser returned unexpected boolean (true)');
}

$testHelper->printNewLine()->printText('Setting up value to "test-key"...')->printNewLine();
$Psr16Adapter->set('test-key', $value);

if($Psr16Adapter->get('test-key') === $value){
$testHelper->printPassText('2/6 Psr16 getter returned expected value: ' . $value);
$testHelper->printPassText('2/9 Psr16 getter returned expected value: ' . $value);
}else{
$testHelper->printFailText('2/6 Psr16 getter returned unexpected value: ' . $value);
$testHelper->printFailText('2/9 Psr16 getter returned unexpected value: ' . $value);
}

$testHelper->printNewLine()->printText('Deleting key "test-key"...')->printNewLine();
$Psr16Adapter->delete('test-key');

if(!$Psr16Adapter->has('test-key')){
$testHelper->printPassText('3/6 Psr16 hasser returned expected boolean (false)');
$testHelper->printPassText('3/9 Psr16 hasser returned expected boolean (false)');
}else{
$testHelper->printFailText('3/6 Psr16 hasser returned unexpected boolean (true)');
$testHelper->printFailText('3/9 Psr16 hasser returned unexpected boolean (true)');
}

$testHelper->printNewLine()->printText('Setting up value to "test-key, test-key2, test-key3"...')->printNewLine();
Expand All @@ -51,9 +51,16 @@

$values = $Psr16Adapter->getMultiple(['test-key', 'test-key2', 'test-key3']);
if(count(array_filter($values)) === 3){
$testHelper->printPassText('4/6 Psr16 multiple getters returned expected values (3)');
$testHelper->printPassText('4/9 Psr16 multiple getters returned expected values (3)');
}else{
$testHelper->printFailText('4/6 Psr16 getters(3) returned unexpected values.');
$testHelper->printFailText('4/9 Psr16 getters(3) returned unexpected values.');
}

$values = $Psr16Adapter->getMultiple(new ArrayObject(['test-key', 'test-key2', 'test-key3']));
if(count(array_filter($values)) === 3){
$testHelper->printPassText('5/9 Psr16 multiple getters with Traversable returned expected values (3)');
}else{
$testHelper->printFailText('5/9 Psr16 getters(3) with Traversable returned unexpected values.');
}

$testHelper->printNewLine()->printText('Clearing whole cache ...')->printNewLine();
Expand All @@ -67,18 +74,53 @@
]);

if($Psr16Adapter->has('test-key') && $Psr16Adapter->has('test-key2') && $Psr16Adapter->has('test-key3')){
$testHelper->printPassText('5/6 Psr16 hasser returned expected booleans (true)');
$testHelper->printPassText('6/9 Psr16 hasser returned expected booleans (true)');
}else{
$testHelper->printFailText('6/9 Psr16 hasser returned one or more unexpected boolean (false)');
}

$testHelper->printNewLine()->printText('Clearing whole cache ...')->printNewLine();
$Psr16Adapter->clear();

$testHelper->printText('Setting multiple values using a Traversable to "test-key, test-key2, test-key3"...')->printNewLine();
$Psr16Adapter->setMultiple(new ArrayObject([
'test-key' => $value,
'test-key2' => $value,
'test-key3' => $value
]));

if($Psr16Adapter->has('test-key') && $Psr16Adapter->has('test-key2') && $Psr16Adapter->has('test-key3')){
$testHelper->printPassText('7/9 Psr16 hasser returned expected booleans (true)');
}else{
$testHelper->printFailText('5/6 Psr16 hasser returned one or more unexpected boolean (false)');
$testHelper->printFailText('7/9 Psr16 hasser returned one or more unexpected boolean (false)');
}

$testHelper->printNewLine()->printText('Deleting up keys "test-key, test-key2, test-key3"...')->printNewLine();
$Psr16Adapter->deleteMultiple(['test-key', 'test-key2', 'test-key3']);

if(!$Psr16Adapter->has('test-key') && !$Psr16Adapter->has('test-key2') && !$Psr16Adapter->has('test-key3')){
$testHelper->printPassText('6/6 Psr16 hasser returned expected booleans (false)');
$testHelper->printPassText('8/9 Psr16 hasser returned expected booleans (false)');
}else{
$testHelper->printFailText('6/6 Psr16 hasser returned one or more unexpected boolean (true)');
$testHelper->printFailText('8/9 Psr16 hasser returned one or more unexpected boolean (true)');
}

$testHelper->printNewLine()->printText('Clearing whole cache ...')->printNewLine();
$Psr16Adapter->clear();
$testHelper->printText('Setting up value to "test-key, test-key2, test-key3"...')->printNewLine();
$Psr16Adapter->setMultiple([
'test-key' => $value,
'test-key2' => $value,
'test-key3' => $value,
]);

$testHelper->printText('Deleting up keys "test-key, test-key2, test-key3"... from a Traversable')->printNewLine();
$traversable = new ArrayObject(['test-key', 'test-key2', 'test-key3']);
$Psr16Adapter->deleteMultiple($traversable);

if (!$Psr16Adapter->has('test-key') && !$Psr16Adapter->has('test-key2') && !$Psr16Adapter->has('test-key3')) {
$testHelper->printPassText('9/9 Psr16 hasser returned expected booleans (false)');
} else {
$testHelper->printFailText('9/9 Psr16 hasser returned one or more unexpected boolean (true)');
}

$testHelper->terminateTest();
$testHelper->terminateTest();

0 comments on commit 1dcdc4c

Please sign in to comment.