Skip to content

Commit f0d949b

Browse files
Fix Cache::many() with small numeric keys (#48423)
* Update Repository.php * Update CacheRepositoryTest.php * Update Repository.php * Update Repository.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 6e1a5c8 commit f0d949b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Illuminate/Cache/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected function handleManyResult($keys, $key, $value)
163163
if (is_null($value)) {
164164
$this->event(new CacheMissed($key));
165165

166-
return isset($keys[$key]) ? value($keys[$key]) : null;
166+
return (isset($keys[$key]) && ! array_is_list($keys)) ? value($keys[$key]) : null;
167167
}
168168

169169
// If we found a valid value we will fire the "hit" event and return the value

tests/Cache/CacheRepositoryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public function testGetReturnsMultipleValuesFromCacheWhenGivenAnArrayWithDefault
5858
$this->assertEquals(['foo' => 'default', 'bar' => 'baz'], $repo->get(['foo' => 'default', 'bar']));
5959
}
6060

61+
public function testGetReturnsMultipleValuesFromCacheWhenGivenAnArrayOfOneTwoThree()
62+
{
63+
$repo = $this->getRepository();
64+
$repo->getStore()->shouldReceive('many')->once()->with([1, 2, 3])->andReturn([1 => null, 2 => null, 3 => null]);
65+
$this->assertEquals([1 => null, 2 => null, 3 => null], $repo->get([1, 2, 3]));
66+
}
67+
6168
public function testDefaultValueIsReturned()
6269
{
6370
$repo = $this->getRepository();

0 commit comments

Comments
 (0)