Skip to content

Commit a493425

Browse files
authored
Merge pull request #29038 from laravel/5.5-cache-set-multiple
[5.5] Fixed cache repository setMultiple with an iterator
2 parents 17fe4ca + 622f56e commit a493425

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Illuminate/Cache/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function putMany(array $values, $minutes)
229229
*/
230230
public function setMultiple($values, $ttl = null)
231231
{
232-
$this->putMany($values, $ttl);
232+
$this->putMany(is_array($values) ? $values : iterator_to_array($values), $ttl);
233233
}
234234

235235
/**

tests/Cache/CacheRepositoryTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use DateInterval;
77
use Mockery as m;
8+
use ArrayIterator;
89
use DateTimeImmutable;
910
use Illuminate\Support\Carbon;
1011
use PHPUnit\Framework\TestCase;
@@ -113,14 +114,22 @@ public function testPuttingMultipleItemsInCache()
113114
$repo->put(['foo' => 'bar', 'bar' => 'baz'], 1);
114115
}
115116

116-
public function testSettingMultipleItemsInCache()
117+
public function testSettingMultipleItemsInCacheArray()
117118
{
118119
// Alias of PuttingMultiple
119120
$repo = $this->getRepository();
120121
$repo->getStore()->shouldReceive('putMany')->once()->with(['foo' => 'bar', 'bar' => 'baz'], 1);
121122
$repo->setMultiple(['foo' => 'bar', 'bar' => 'baz'], 1);
122123
}
123124

125+
public function testSettingMultipleItemsInCacheIterator()
126+
{
127+
// Alias of PuttingMultiple
128+
$repo = $this->getRepository();
129+
$repo->getStore()->shouldReceive('putMany')->once()->with(['foo' => 'bar', 'bar' => 'baz'], 1);
130+
$repo->setMultiple(new ArrayIterator(['foo' => 'bar', 'bar' => 'baz']), 1);
131+
}
132+
124133
public function testPutWithDatetimeInPastOrZeroSecondsDoesntSaveItem()
125134
{
126135
$repo = $this->getRepository();

0 commit comments

Comments
 (0)