/** * Return a new RepoModels object with models sorted using the compare closure * * @param Closure $closure must return true for each item * @return RepoModels Filtered models */ public function sort(Closure $closure) { return $this->current->sort($closure); }
/** * @covers ::sort */ public function testSort() { $city1 = new City(['id' => 1]); $city2 = new City(['id' => 3]); $city3 = new City(['id' => 8]); $source = [$city1, $city3, $city2]; $models = new Models($source); $sorted = $models->sort(function ($city1, $city2) { return $city1->id - $city2->id; }); $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $sorted); $this->assertEquals([$city1, $city2, $city3], Objects::toArray($sorted->all())); }