/** * Stub for writes * * @param \Trismegiste\Mondrian\Parser\PhpFile $file */ public function write(PhpFile $file) { $fch = $file->getRealPath(); $stmts = iterator_to_array($file->getIterator()); $prettyPrinter = new \PHPParser_PrettyPrinter_Default(); $this->storage[basename($fch)] = $this->getMockFile($fch, "<?php\n\n" . $prettyPrinter->prettyPrint($stmts)); $this->invocationMocker->invoke(new \PHPUnit_Framework_MockObject_Invocation_Object('VirtualPhpDumper', 'write', array(basename($fch)), $this)); }
public function stubbedTestedWrite(PhpFile $file) { $this->assertEquals('/addicted/to/Chaos.php', $file->getRealPath()); $generated = $file->getIterator(); $this->assertCount(2, $generated); $this->assertInstanceOf('\\PHPParser_Node_Stmt_Namespace', $generated[0]); $this->assertInstanceOf('\\PHPParser_Node_Stmt_Interface', $generated[1]); $interf = $generated[1]->stmts; $this->assertInstanceOf('\\PHPParser_Node_Stmt_ClassMethod', $interf[0]); $this->assertEquals('forsaken', $interf[0]->name); }
public function testWithTraverser() { $this->context->expects($this->once())->method('hasNewContract')->with('Pull\\Me\\Under')->will($this->returnValue(true)); $this->context->expects($this->once())->method('getNewContract')->with('Pull\\Me\\Under')->will($this->returnValue('Awake')); $classNode = new \PHPParser_Node_Stmt_Class('Victory', array('stmts' => array(new \PHPParser_Node_Stmt_ClassMethod('holy', array('params' => array(new \PHPParser_Node_Param('war', null, new \PHPParser_Node_Name('Pull\\Me\\Under'))))))), array('comments' => array(new \PHPParser_Comment('@mondrian contractor SomeNewContract')))); $file = new \Trismegiste\Mondrian\Parser\PhpFile('/I/Am/Victory.php', array($classNode)); $traverser = new \PHPParser_NodeTraverser(); $traverser->addVisitor($this->visitor); $this->assertFalse($file->isModified()); $traverser->traverse(array($file)); $this->assertTrue($file->isModified()); $this->assertEquals('Awake', (string) $classNode->stmts[0]->params[0]->type); }