Exemple #1
0
         $collection = new Collection(['data' => [1, 2, 3, 4, 5]]);
         $filter = function ($item) {
             return ++$item;
         };
         $result = $collection->each($filter);
         expect($result)->toBe($collection);
         expect($result->data())->toBe([2, 3, 4, 5, 6]);
     });
 });
 describe("->find()", function () {
     it("extracts items from a collection according a filter", function () {
         $collection = new Collection(['data' => array_merge(array_fill(0, 10, 1), array_fill(0, 10, 2))]);
         $filter = function ($item) {
             return $item === 1;
         };
         $result = $collection->find($filter);
         expect($result)->toBeAnInstanceOf(Collection::class);
         expect($result->data())->toBe(array_fill(0, 10, 1));
     });
 });
 describe("->map()", function () {
     it("applies a Closure to a copy of all data in the collection", function () {
         $collection = new Collection(['data' => [1, 2, 3, 4, 5]]);
         $filter = function ($item) {
             return ++$item;
         };
         $result = $collection->map($filter);
         expect($result)->not->toBe($collection);
         expect($result->data())->toBe([2, 3, 4, 5, 6]);
     });
 });