lexer = new Lexer; } /** * @dataProvider provideTestError */ public function testError($code, $message) { try { $this->lexer->startLexing($code); } catch (Error $e) { $this->assertSame($message, $e->getMessage()); return; } $this->fail('Expected PhpParser\Error'); } public function provideTestError() { return array( array('lexer->startLexing($code); while ($id = $this->lexer->getNextToken($value, $startAttributes, $endAttributes)) { $token = array_shift($tokens); $this->assertSame($token[0], $id); $this->assertSame($token[1], $value); $this->assertEquals($token[2], $startAttributes); $this->assertEquals($token[3], $endAttributes); } } public function provideTestLex() { return array( // tests conversion of closing PHP tag and drop of whitespace and opening tags array( 'plaintext', array( array( Parser::T_STRING, 'tokens', array('startLine' => 1), array('endLine' => 1) ), array( ord(';'), '?>', array('startLine' => 1), array('endLine' => 1) ), array( Parser::T_INLINE_HTML, 'plaintext', array('startLine' => 1), array('endLine' => 1) ), ) ), // tests line numbers array( ' 2), array('endLine' => 2) ), array( Parser::T_STRING, 'token', array('startLine' => 2), array('endLine' => 2) ), array( ord('$'), '$', array( 'startLine' => 3, 'comments' => array(new Comment\Doc('/** doc' . "\n" . 'comment */', 2)) ), array('endLine' => 3) ), ) ), // tests comment extraction array( ' 2, 'comments' => array( new Comment('/* comment */', 1), new Comment('// comment' . "\n", 1), new Comment\Doc('/** docComment 1 */', 2), new Comment\Doc('/** docComment 2 */', 2), ), ), array('endLine' => 2) ), ) ), // tests differing start and end line array( ' 1), array('endLine' => 2) ), ) ), ); } /** * @dataProvider provideTestHaltCompiler */ public function testHandleHaltCompiler($code, $remaining) { $this->lexer->startLexing($code); while (Parser::T_HALT_COMPILER !== $this->lexer->getNextToken()); $this->assertSame($this->lexer->handleHaltCompiler(), $remaining); $this->assertSame(0, $this->lexer->getNextToken()); } public function provideTestHaltCompiler() { return array( array('Remaining Text', 'Remaining Text'), //array('