/** * @covers ::Sort */ public function testSort() { $obj1 = new TestObject(5); $obj2 = new TestObject(10); $obj3 = new TestObject(32); $objects = Objects::fromArray(array($obj1, $obj3, $obj2)); $sorted = Objects::sort($objects, function ($item1, $item2) { return $item1->id - $item2->id; }); $sortedArray = iterator_to_array($sorted); $this->assertSame(array($obj1, $obj2, $obj3), $sortedArray); }
/** * Sort the models collection using a comparation closure * * @param Closure $closure * @return array */ public function sort(Closure $closure) { $sorted = clone $this; $sorted->models = Objects::sort($sorted->models, $closure); return $sorted; }