Skip to content

Commit

Permalink
Fixed cache repository getMultiple implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Jul 2, 2019
1 parent c0f28b4 commit 0b4c144
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,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
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,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 0b4c144

Please sign in to comment.