File tree 2 files changed +13
-22
lines changed
src/Illuminate/View/Concerns
2 files changed +13
-22
lines changed Original file line number Diff line number Diff line change 3
3
namespace Illuminate \View \Concerns ;
4
4
5
5
use Countable ;
6
- use Traversable ;
7
6
use Illuminate \Support \Arr ;
8
7
9
8
trait ManagesLoops
@@ -23,13 +22,7 @@ trait ManagesLoops
23
22
*/
24
23
public function addLoop ($ data )
25
24
{
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 ;
33
26
34
27
$ parent = Arr::last ($ this ->loopsStack );
35
28
Original file line number Diff line number Diff line change @@ -555,26 +555,24 @@ public function testAddingLoops()
555
555
$ this ->assertEquals ([$ expectedLoop ], $ factory ->getLoopStack ());
556
556
}
557
557
558
- public function testAddingTraversableLoop ()
558
+ public function testAddingLoopDoesNotCloseGenerator ()
559
559
{
560
560
$ factory = $ this ->getFactory ();
561
561
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 ();
563
570
564
571
$ factory ->addLoop ($ data );
565
572
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
+ }
578
576
}
579
577
580
578
public function testAddingUncountableLoop ()
You can’t perform that action at this time.
0 commit comments