Skip to content

Commit 8ce1108

Browse files
authored
Merge pull request #29046 from laravel/5.5-cache-get-multiple-fix
[5.5] Fixed cache repository getMultiple implementation
2 parents 65a4df4 + 338deed commit 8ce1108

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/Illuminate/Cache/Repository.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,13 @@ public function many(array $keys)
123123
*/
124124
public function getMultiple($keys, $default = null)
125125
{
126-
if (is_null($default)) {
127-
return $this->many($keys);
128-
}
126+
$defaults = [];
129127

130128
foreach ($keys as $key) {
131-
if (! isset($default[$key])) {
132-
$default[$key] = null;
133-
}
129+
$defaults[$key] = $default;
134130
}
135131

136-
return $this->many($default);
132+
return $this->many($defaults);
137133
}
138134

139135
/**

tests/Cache/CacheRepositoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ public function testClearingWholeCache()
223223
public function testGettingMultipleValuesFromCache()
224224
{
225225
$keys = ['key1', 'key2', 'key3'];
226-
$default = ['key2' => 5];
226+
$default = 5;
227227

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

233233
public function testRemovingMultipleKeys()

0 commit comments

Comments
 (0)