Beispiel #1
0
 /**
  * @test
  */
 public function shouldCompareByExpression()
 {
     //given
     $mock1 = Mock::mock('Foo');
     Mock::when($mock1)->method()->thenReturn(1);
     $mock2 = Mock::mock('Foo');
     Mock::when($mock2)->method()->thenReturn(2);
     $comparator = Comparator::compareBy('method()');
     //when
     $lesser = $comparator($mock1, $mock2);
     $greater = $comparator($mock2, $mock1);
     $equal = $comparator($mock1, $mock1);
     //then
     $this->assertEquals(-1, $lesser);
     $this->assertEquals(1, $greater);
     $this->assertEquals(0, $equal);
 }
Beispiel #2
0
 /**
  * @test
  */
 public function shouldSortArrayIndependentlyFromInitialOrder()
 {
     //given
     $product1 = new Product(array('name' => 'a'));
     $product2 = new Product(array('name' => 'b'));
     $product3 = new Product(array('name' => 'c'));
     $array1 = array($product1, $product2, $product3);
     $array2 = array($product2, $product1, $product3);
     $array3 = array($product3, $product1, $product2);
     $comparator = Comparator::compareBy('name');
     //when
     $sorted1 = Arrays::sort($array1, $comparator);
     $sorted2 = Arrays::sort($array2, $comparator);
     $sorted3 = Arrays::sort($array3, $comparator);
     //then
     $this->assertEquals($sorted1, $sorted2);
     $this->assertEquals($sorted2, $sorted3);
 }