mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 20:20:15 +02:00
full visitor pattern withh double dispatch
This commit is contained in:
51
Tests/Visitor/VisitorTest.php
Normal file
51
Tests/Visitor/VisitorTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\Tests\Visitor;
|
||||
|
||||
use DesignPatterns\Visitor;
|
||||
|
||||
/**
|
||||
* VisitorTest tests the visitor pattern
|
||||
*/
|
||||
class VisitorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $visitor;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->visitor = new Visitor\RolePrintVisitor();
|
||||
}
|
||||
|
||||
public function getRole()
|
||||
{
|
||||
return array(
|
||||
array(new Visitor\User("Dominik"), 'Role: User Dominik'),
|
||||
array(new Visitor\Group("Administrators"), 'Role: Group: Administrators')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getRole
|
||||
*/
|
||||
public function testVisitSomeRole(Visitor\Role $role, $expect)
|
||||
{
|
||||
$this->expectOutputString($expect);
|
||||
$role->accept($this->visitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Mock
|
||||
*/
|
||||
public function testUnknownObject()
|
||||
{
|
||||
$mock = $this->getMockForAbstractClass('DesignPatterns\Visitor\Role');
|
||||
$mock->accept($this->visitor);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user