public function testSort() { $original = [3, 1, 2]; $expected = [1, 2, 3]; $collection = new Collection($original); $sorted = $collection->sort(function ($a, $b) { if ($a == $b) { return 0; } return $a < $b ? -1 : +1; }); $this->assertInstanceOf(Collection::class, $sorted); $this->assertNotSame($collection, $sorted); $this->assertSame($expected, $sorted->toArray()); $this->assertSame($original, $collection->toArray()); }