| @@ 263-274 (lines=12) @@ | ||
| 260 | * |
|
| 261 | * @return void |
|
| 262 | */ |
|
| 263 | public function testSort() |
|
| 264 | { |
|
| 265 | $this->collection->sort(function($a, $b) { |
|
| 266 | if ($a === $b) { |
|
| 267 | return 0; |
|
| 268 | } |
|
| 269 | ||
| 270 | return $a > $b ? -1 : 1; |
|
| 271 | }); |
|
| 272 | ||
| 273 | $this->assertAttributeEquals([3,2,1], 'elements', $this->collection); |
|
| 274 | } |
|
| 275 | ||
| 276 | /** |
|
| 277 | * Test sorting collection by callback and retaining element keys/indicies |
|
| @@ 281-292 (lines=12) @@ | ||
| 278 | * |
|
| 279 | * @return void |
|
| 280 | */ |
|
| 281 | public function testAsort() |
|
| 282 | { |
|
| 283 | $this->collection->asort(function($a, $b) { |
|
| 284 | if ($a === $b) { |
|
| 285 | return 0; |
|
| 286 | } |
|
| 287 | ||
| 288 | return $a > $b ? -1 : 1; |
|
| 289 | }); |
|
| 290 | ||
| 291 | $this->assertAttributeEquals([2 => 3, 1 => 2, 0 => 1], 'elements', $this->collection); |
|
| 292 | } |
|
| 293 | ||
| 294 | /** |
|
| 295 | * Test applying a callback to each element of the collection |
|