protected function setUp() { $this->stream = $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock(); $this->expressionParser = $this->getMockBuilder('Twig_ExpressionParser')->disableOriginalConstructor()->getMock(); $this->parser = $this->getMockBuilder('Twig_Parser')->disableOriginalConstructor()->getMock(); $this->parser->expects($this->any())->method('getStream')->will($this->returnValue($this->stream)); $this->parser->expects($this->any())->method('getExpressionParser')->will($this->returnValue($this->expressionParser)); $this->compiler = $this->getMockBuilder('Twig_Compiler')->disableOriginalConstructor()->getMock(); $this->tokenParser = new PlaceholderTokenParser(); $this->tokenParser->setParser($this->parser); }
public function testParse() { $startToken = new \Twig_Token(\Twig_Token::NAME_TYPE, 'placeholder', 12); $stream = new \Twig_TokenStream([new \Twig_Token(\Twig_Token::NAME_TYPE, 'test_position', 12), new \Twig_Token(\Twig_Token::NAME_TYPE, 'with', 12), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 12), new \Twig_Token(\Twig_Token::EOF_TYPE, '', 12)]); $expressionParser = $this->getMockBuilder('\\Twig_ExpressionParser')->disableOriginalConstructor()->getMock(); $parser = $this->getMockBuilder('\\Twig_Parser')->disableOriginalConstructor()->getMock(); $parser->expects($this->once())->method('getStream')->will($this->returnValue($stream)); $parser->expects($this->once())->method('getExpressionParser')->will($this->returnValue($expressionParser)); $expressionParser->expects($this->once())->method('parseExpression')->will($this->returnValue(null)); $this->placeholder->setParser($parser); $resultNode = $this->placeholder->parse($startToken); $this->assertEquals(12, $resultNode->getLine()); $this->assertEquals('placeholder', $resultNode->getNodeTag()); }