Skip to content

Commit e3464c0

Browse files
author
FlorianLB
committedOct 30, 2013
add tests for ObjectIsEqual
1 parent 4ceddb8 commit e3464c0

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
v1.0.0 (master)
2+
=====
3+
* add more tests
4+
5+
v0.1.0 : Initial version
6+
=====
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace CleverAge\Ruler\Test\Fixtures;
4+
5+
class BarObject
6+
{
7+
protected $id;
8+
9+
public function __construct($id = null)
10+
{
11+
$this->id = $id;
12+
}
13+
14+
public function getId()
15+
{
16+
return $this->id;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace CleverAge\Ruler\Test\Fixtures;
4+
5+
class FooChildObject extends FooObject
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace CleverAge\Ruler\Test\Fixtures;
4+
5+
class FooObject
6+
{
7+
protected $id;
8+
9+
public function __construct($id = null)
10+
{
11+
$this->id = $id;
12+
}
13+
14+
public function getId()
15+
{
16+
return $this->id;
17+
}
18+
19+
public function setId($id)
20+
{
21+
$this->id = $id;
22+
23+
return $this;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)
Please sign in to comment.