Пример #1
0
 /**
  * @test
  */
 public function shouldProperlyCompareUsingReversed()
 {
     //given
     $reversed = Comparator::reverse(Comparator::natural());
     //when
     $greater = $reversed(1, 2);
     $lesser = $reversed(2, 1);
     $equal = $reversed(1, 1);
     //then
     $this->assertEquals(-1, $lesser);
     $this->assertEquals(1, $greater);
     $this->assertEquals(0, $equal);
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldSortArrayByCompoundComparator()
 {
     //given
     $product1 = new Product(array('name' => 'b', 'description' => '2'));
     $product2 = new Product(array('name' => 'a', 'description' => '1'));
     $product3 = new Product(array('name' => 'a', 'description' => '2'));
     $array = array($product3, $product1, $product2);
     $comparator = Comparator::compound(Comparator::reverse(Comparator::compareBy('name')), Comparator::compareBy('description'));
     //when
     $sorted = Arrays::sort($array, $comparator);
     //then
     Assert::thatArray($sorted)->containsExactly($product1, $product2, $product3);
 }