PHP7 Visitor

This commit is contained in:
Dominik Liebler
2016-09-22 11:29:48 +02:00
parent 19fff0aed9
commit 1c30978a70
9 changed files with 72 additions and 149 deletions

View File

@@ -4,42 +4,34 @@ namespace DesignPatterns\Tests\Visitor\Tests;
use DesignPatterns\Behavioral\Visitor;
/**
* VisitorTest tests the visitor pattern.
*/
class VisitorTest extends \PHPUnit_Framework_TestCase
{
protected $visitor;
/**
* @var Visitor\RoleVisitor
*/
private $visitor;
protected function setUp()
{
$this->visitor = new Visitor\RolePrintVisitor();
$this->visitor = new Visitor\RoleVisitor();
}
public function getRole()
public function provideRoles()
{
return array(
array(new Visitor\User('Dominik'), 'Role: User Dominik'),
array(new Visitor\Group('Administrators'), 'Role: Group: Administrators'),
);
return [
[new Visitor\User('Dominik')],
[new Visitor\Group('Administrators')],
];
}
/**
* @dataProvider getRole
* @dataProvider provideRoles
*
* @param Visitor\Role $role
*/
public function testVisitSomeRole(Visitor\Role $role, $expect)
public function testVisitSomeRole(Visitor\Role $role)
{
$this->expectOutputString($expect);
$role->accept($this->visitor);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Mock
*/
public function testUnknownObject()
{
$mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role');
$mock->accept($this->visitor);
$this->assertSame($role, $this->visitor->getVisited()[0]);
}
}