expect($result->data())->toBe([1, 2, 3, 4, 5]); }); it("sorts a collection using a compare function", function () { $collection = new Collection(['data' => ['Alan', 'Dave', 'betsy', 'carl']]); $result = $collection->sort('strcasecmp'); expect($result->data())->toBe(['Alan', 'betsy', 'carl', 'Dave']); }); it("sorts a collection by keys", function () { $collection = new Collection(['data' => [5 => 6, 3 => 7, 4 => 8, 1 => 9, 2 => 10]]); $result = $collection->sort(null, 'ksort'); expect($result->keys())->toBe([1, 2, 3, 4, 5]); }); it("throws an exception if the sort function is not callable", function () { $closure = function () { $collection = new Collection(['data' => [1, 2, 3, 4, 5]]); $collection->sort(null, 'mysort'); }; expect($closure)->toThrow(new InvalidArgumentException("The passed parameter is not a valid sort function.")); }); }); describe("->offsetExists()", function () { it("returns true if a element exist", function () { $collection = new Collection(); $collection[] = 'foo'; $collection[] = null; expect(isset($collection[0]))->toBe(true); expect(isset($collection[1]))->toBe(true); }); it("returns false if a element doesn't exist", function () { $collection = new Collection(); expect(isset($collection[0]))->toBe(false);