mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP7 Visitor
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user