|
4 | 4 |
|
5 | 5 | use DesignPatterns\Behavioral\Visitor; |
6 | 6 |
|
7 | | -/** |
8 | | - * VisitorTest tests the visitor pattern. |
9 | | - */ |
10 | 7 | class VisitorTest extends \PHPUnit_Framework_TestCase |
11 | 8 | { |
12 | | - protected $visitor; |
| 9 | + /** |
| 10 | + * @var Visitor\RoleVisitor |
| 11 | + */ |
| 12 | + private $visitor; |
13 | 13 |
|
14 | 14 | protected function setUp() |
15 | 15 | { |
16 | | - $this->visitor = new Visitor\RolePrintVisitor(); |
| 16 | + $this->visitor = new Visitor\RoleVisitor(); |
17 | 17 | } |
18 | 18 |
|
19 | | - public function getRole() |
| 19 | + public function provideRoles() |
20 | 20 | { |
21 | | - return array( |
22 | | - array(new Visitor\User('Dominik'), 'Role: User Dominik'), |
23 | | - array(new Visitor\Group('Administrators'), 'Role: Group: Administrators'), |
24 | | - ); |
| 21 | + return [ |
| 22 | + [new Visitor\User('Dominik')], |
| 23 | + [new Visitor\Group('Administrators')], |
| 24 | + ]; |
25 | 25 | } |
26 | 26 |
|
27 | 27 | /** |
28 | | - * @dataProvider getRole |
| 28 | + * @dataProvider provideRoles |
| 29 | + * |
| 30 | + * @param Visitor\Role $role |
29 | 31 | */ |
30 | | - public function testVisitSomeRole(Visitor\Role $role, $expect) |
| 32 | + public function testVisitSomeRole(Visitor\Role $role) |
31 | 33 | { |
32 | | - $this->expectOutputString($expect); |
33 | 34 | $role->accept($this->visitor); |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * @expectedException \InvalidArgumentException |
38 | | - * @expectedExceptionMessage Mock |
39 | | - */ |
40 | | - public function testUnknownObject() |
41 | | - { |
42 | | - $mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role'); |
43 | | - $mock->accept($this->visitor); |
| 35 | + $this->assertSame($role, $this->visitor->getVisited()[0]); |
44 | 36 | } |
45 | 37 | } |
0 commit comments