Skip to content

Commit d0a2613

Browse files
committed
fix test
1 parent 3fd1b23 commit d0a2613

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/Illuminate/View/Concerns/ManagesLoops.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Illuminate\View\Concerns;
44

55
use Countable;
6-
use Traversable;
76
use Illuminate\Support\Arr;
87

98
trait ManagesLoops
@@ -23,13 +22,7 @@ trait ManagesLoops
2322
*/
2423
public function addLoop($data)
2524
{
26-
$length = null;
27-
28-
if (is_array($data) || $data instanceof Countable) {
29-
$length = count($data);
30-
} elseif ($data instanceof Traversable) {
31-
$length = iterator_count($data);
32-
}
25+
$length = is_array($data) || $data instanceof Countable ? count($data) : null;
3326

3427
$parent = Arr::last($this->loopsStack);
3528

tests/View/ViewFactoryTest.php

+12-14
Original file line numberDiff line numberDiff line change
@@ -555,26 +555,24 @@ public function testAddingLoops()
555555
$this->assertEquals([$expectedLoop], $factory->getLoopStack());
556556
}
557557

558-
public function testAddingTraversableLoop()
558+
public function testAddingLoopDoesNotCloseGenerator()
559559
{
560560
$factory = $this->getFactory();
561561

562-
$data = new \DatePeriod(\Carbon\Carbon::today(), \Carbon\CarbonInterval::day(), \Carbon\Carbon::tomorrow()->endOfDay());
562+
$data = (new class {
563+
public function generate()
564+
{
565+
for($count = 0; $count < 3; $count++) {
566+
yield ['a', 'b'];
567+
}
568+
}
569+
})->generate();
563570

564571
$factory->addLoop($data);
565572

566-
$expectedLoop = [
567-
'iteration' => 0,
568-
'index' => 0,
569-
'remaining' => 2,
570-
'count' => 2,
571-
'first' => true,
572-
'last' => false,
573-
'depth' => 1,
574-
'parent' => null,
575-
];
576-
577-
$this->assertEquals([$expectedLoop], $factory->getLoopStack());
573+
foreach ($data as $chunk) {
574+
$this->assertEquals(['a', 'b'], $chunk);
575+
}
578576
}
579577

580578
public function testAddingUncountableLoop()

0 commit comments

Comments
 (0)