/**
* Tests that the Collection::sort method works appropriately.
*/
public function testCollectionSort()
{
$collection = new Collection(array('data' => array(5, 3, 4, 1, 2)));
$collection->sort();
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual($expected, $collection->to('array'));
$collection = new Collection(array('data' => array('alan', 'dave', 'betsy', 'carl')));
$expected = array('alan', 'betsy', 'carl', 'dave');
$this->assertEqual($expected, $collection->sort()->to('array'));
$collection = new Collection(array('data' => array('Alan', 'Dave', 'betsy', 'carl')));
$expected = array('Alan', 'betsy', 'carl', 'Dave');
$this->assertEqual($expected, $collection->sort('strcasecmp')->to('array'));
$collection = new Collection(array('data' => array(5, 3, 4, 1, 2)));
$collection->sort(function ($a, $b) {
if ($a === $b) {
return 0;
}
return $b > $a ? 1 : -1;
});
$expected = array(5, 4, 3, 2, 1);
$this->assertEqual($expected, $collection->to('array'));
$collection = new Collection(array('data' => array(5, 3, 4, 1, 2)));
$result = $collection->sort('blahgah');
$this->assertEqual($collection->to('array'), $result->to('array'));
}