public function testModifying()
{
$str1Node = new String_('Foo');
$str2Node = new String_('Bar');
$printNode = new Expr\Print_($str1Node);
// first visitor changes the node, second verifies the change
$visitor1 = $this->getMockBuilder('PhpParser\\NodeVisitor')->getMock();
$visitor2 = $this->getMockBuilder('PhpParser\\NodeVisitor')->getMock();
// replace empty statements with string1 node
$visitor1->expects($this->at(0))->method('beforeTraverse')->with(array())->will($this->returnValue(array($str1Node)));
$visitor2->expects($this->at(0))->method('beforeTraverse')->with(array($str1Node));
// replace string1 node with print node
$visitor1->expects($this->at(1))->method('enterNode')->with($str1Node)->will($this->returnValue($printNode));
$visitor2->expects($this->at(1))->method('enterNode')->with($printNode);
// replace string1 node with string2 node
$visitor1->expects($this->at(2))->method('enterNode')->with($str1Node)->will($this->returnValue($str2Node));
$visitor2->expects($this->at(2))->method('enterNode')->with($str2Node);
// replace string2 node with string1 node again
$visitor1->expects($this->at(3))->method('leaveNode')->with($str2Node)->will($this->returnValue($str1Node));
$visitor2->expects($this->at(3))->method('leaveNode')->with($str1Node);
// replace print node with string1 node again
$visitor1->expects($this->at(4))->method('leaveNode')->with($printNode)->will($this->returnValue($str1Node));
$visitor2->expects($this->at(4))->method('leaveNode')->with($str1Node);
// replace string1 node with empty statements again
$visitor1->expects($this->at(5))->method('afterTraverse')->with(array($str1Node))->will($this->returnValue(array()));
$visitor2->expects($this->at(5))->method('afterTraverse')->with(array());
$traverser = new NodeTraverser();
$traverser->addVisitor($visitor1);
$traverser->addVisitor($visitor2);
// as all operations are reversed we end where we start
$this->assertEquals(array(), $traverser->traverse(array()));
}