|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CleverAge\Ruler\Test\Rule; |
| 4 | + |
| 5 | +use CleverAge\Ruler\Rule\ObjectIsEqual; |
| 6 | +use CleverAge\Ruler\Test\Fixtures\FooObject as Foo; |
| 7 | +use CleverAge\Ruler\Test\Fixtures\BarObject as Bar; |
| 8 | +use CleverAge\Ruler\Test\Fixtures\FooChildObject as FooChild; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author FlorianLB |
| 12 | + */ |
| 13 | +class ObjectIsEqualTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider satifyingRules |
| 17 | + * @test |
| 18 | + */ |
| 19 | + public function it_should_be_satisfied($satisfyingRule) |
| 20 | + { |
| 21 | + $this->assertTrue($satisfyingRule->isSatisfied()); |
| 22 | + } |
| 23 | + |
| 24 | + public function satifyingRules() |
| 25 | + { |
| 26 | + $foo = new Foo(); |
| 27 | + |
| 28 | + return array( |
| 29 | + array(new ObjectIsEqual($foo, $foo)), |
| 30 | + array(new ObjectIsEqual($foo, $foo->setId(1))), |
| 31 | + array(new ObjectIsEqual(new Foo(2), new Foo(2))), |
| 32 | + array(new ObjectIsEqual(new Foo(2), new FooChild(2))), |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @dataProvider unsatifyingRules |
| 38 | + * @test |
| 39 | + */ |
| 40 | + public function it_should_not_be_satisfied($unsatisfyingRule) |
| 41 | + { |
| 42 | + $this->setExpectedException('CleverAge\Ruler\Exception\NotSatisfiedException'); |
| 43 | + |
| 44 | + $unsatisfyingRule->isSatisfied(); |
| 45 | + } |
| 46 | + |
| 47 | + public function unsatifyingRules() |
| 48 | + { |
| 49 | + return array( |
| 50 | + array(new ObjectIsEqual(new Foo(), new Bar())), |
| 51 | + array(new ObjectIsEqual(new Foo(2), new Bar(2))), |
| 52 | + array(new ObjectIsEqual(1, new Bar())), |
| 53 | + array(new ObjectIsEqual(new Foo(), 'pony')) |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @test |
| 59 | + */ |
| 60 | + public function it_should_be_instantiable() |
| 61 | + { |
| 62 | + $this->assertInstanceOf( |
| 63 | + 'CleverAge\Ruler\Rule\ObjectIsEqual', |
| 64 | + new ObjectIsEqual(new Foo(), new Bar(), 'getName') |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments