Skip to content

Commit

Permalink
starting unit test for visitor gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Trismegiste committed Sep 15, 2014
1 parent bb9aed3 commit d26f212
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Visitor/VisitorGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class VisitorGateway extends NodeVisitorAbstract implements State\VisitorContext
*/
public function __construct(array $visitor, ReflectionContext $ref, GraphContext $grf, Graph $g)
{
if (!count($visitor)) {
throw new \InvalidArgumentException("The visitors list cannot be empty");
}
$this->graphCtx = $grf;
$this->graph = $g;
$this->reflectionCtx = $ref;
Expand Down
71 changes: 71 additions & 0 deletions tests/Visitor/VisitorGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* Mondrian
*/

namespace Trismegiste\Mondrian\Tests\Visitor;

use Trismegiste\Mondrian\Visitor\VisitorGateway;

/**
* VisitorGatewayTest tests the VisitorGateway
*/
class VisitorGatewayTest extends \PHPUnit_Framework_TestCase
{

protected $sut;
protected $reflectionCtx;
protected $graphCtx;
protected $graph;

private function buildVisitor(array $visitor = [])
{
$this->sut = new VisitorGateway($visitor, $this->reflectionCtx, $this->graphCtx, $this->graph);
}

protected function setUp()
{
$this->reflectionCtx = $this->getMock('Trismegiste\Mondrian\Transform\ReflectionContext');
$this->graphCtx = $this->getMockBuilder('Trismegiste\Mondrian\Transform\GraphContext')
->disableOriginalConstructor()
->getMock();
$this->graph = $this->getMock('Trismegiste\Mondrian\Graph\Graph');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testEmpty()
{
$this->buildVisitor();
}

/**
* @expectedException \InvalidArgumentException
*/
public function testBadState()
{
$this->buildVisitor(['sfd']);
}

public function testStateKey()
{
$state0 = $this->getMock('Trismegiste\Mondrian\Visitor\State\State');
$state0->expects($this->exactly(2))
->method('getName')
->will($this->returnValue('key0'));
$state0->expects($this->once())
->method('setContext');

$state1 = $this->getMock('Trismegiste\Mondrian\Visitor\State\State');
$state1->expects($this->once())
->method('getName')
->will($this->returnValue('key1'));
$state1->expects($this->once())
->method('setContext');

$this->buildVisitor([$state0, $state1]);
}

}

0 comments on commit d26f212

Please sign in to comment.