Beispiel #1
0
 public function test_sort_keeps_order_of_already_sorted_array()
 {
     $records = $this->getUserDataSortedByLastName();
     $data = [];
     foreach ($records as $record) {
         $data[] = new User($record);
     }
     Merge::sort($data, function ($user1, $user2) {
         $comp = strnatcmp($user1->lastName(), $user2->lastName());
         if ($comp > 0) {
             return 1;
         }
         if ($comp < 0) {
             return -1;
         }
         return 0;
     });
     $sorted = $this->getUserDataSortedByLastName();
     $valid = true;
     $count = count($data);
     for ($i = 0; $i < $count; $i++) {
         $user = $data[$i];
         if ($user->lastName() !== $sorted[$i]['lastName']) {
             $valid = false;
         }
     }
     $this->assertTrue($valid);
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function sort(callable $comparator)
 {
     Merge::sort($this->items, $comparator);
 }