public function testSorted()
{
$this->assertEquals([1, 2, 3], sorted([2, 3, 1]));
$this->assertEquals([1, 2, 3], sorted(new \ArrayIterator([2, 3, 1])));
$this->assertEquals(array('carrot' => 'c', 'banana' => 'b', 'apple' => 'a'), sorted(array('carrot' => 'c', 'apple' => 'a', 'banana' => 'b'), true));
$this->assertEquals(['forty two', 'answer', 'the', 'is'], sorted(['the', 'answer', 'is', 'forty two'], true, 'strlen'));
$this->assertEquals(['is', 'the', 'answer', 'forty two'], sorted(['the', 'answer', 'is', 'forty two'], 'strlen'));
$isFruit = function ($v) {
return in_array($v, ['apple', 'orange']);
};
$this->assertEquals(['apple', 'orange', 'cat'], sorted(['orange', 'cat', 'apple'], false, null, function ($v1, $v2) use($isFruit) {
if (!$isFruit($v1)) {
return 1;
}
if (!$isFruit($v2)) {
return -1;
}
return $v1 > $v2;
}));
$this->assertEquals([], sorted([]));
$this->assertEquals([1], sorted([1]));
$this->assertEquals(array('b' => null, 'a' => null), sorted(array('b' => null, 'a' => null)));
$list = [3, 1, 2];
$this->assertEquals([1, 2, 3], sorted($list));
$this->assertEquals([3, 1, 2], $list);
$this->assertEquals([1, 2, 3], call_user_func(sorted, [2, 3, 1]));
$this->assertEquals('\\nspl\\a\\sorted', sorted);
}