Skip to content

Commit

Permalink
Merge pull request #29047 from laravel/5.8-cache-get-multiple-fix
Browse files Browse the repository at this point in the history
[5.8] Fixed cache repository getMultiple implementation
  • Loading branch information
taylorotwell committed Jul 5, 2019
2 parents 28ba780 + 67fad0d commit c4be803
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/Illuminate/Cache/Repository.php
Expand Up @@ -134,17 +134,13 @@ public function many(array $keys)
*/
public function getMultiple($keys, $default = null)
{
if (is_null($default)) {
return $this->many($keys);
}
$defaults = [];

foreach ($keys as $key) {
if (! isset($default[$key])) {
$default[$key] = null;
}
$defaults[$key] = $default;
}

return $this->many($default);
return $this->many($defaults);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Cache/CacheRepositoryTest.php
Expand Up @@ -276,11 +276,11 @@ public function testClearingWholeCache()
public function testGettingMultipleValuesFromCache()
{
$keys = ['key1', 'key2', 'key3'];
$default = ['key2' => 5];
$default = 5;

$repo = $this->getRepository();
$repo->getStore()->shouldReceive('many')->once()->with(['key2', 'key1', 'key3'])->andReturn(['key1' => 1, 'key2' => null, 'key3' => null]);
$this->assertEquals(['key1' => 1, 'key2' => 5, 'key3' => null], $repo->getMultiple($keys, $default));
$repo->getStore()->shouldReceive('many')->once()->with(['key1', 'key2', 'key3'])->andReturn(['key1' => 1, 'key2' => null, 'key3' => null]);
$this->assertEquals(['key1' => 1, 'key2' => 5, 'key3' => 5], $repo->getMultiple($keys, $default));
}

public function testRemovingMultipleKeys()
Expand Down

0 comments on commit c4be803

Please sign in to comment.