public function testForEach() { $stopValue = 3; $loop = 0; $shouldStopAtLoop = 3; $items = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]; $collection = new Collection($items); $collection->each(function ($value) use(&$loop, $stopValue) { $loop++; if ($value == $stopValue) { return false; } }); $this->assertEquals($shouldStopAtLoop, $loop); }
public function __construct($data = null) { parent::__construct(is_null($data) ? $this->data() : $data); }