markTestSkipped('HHVM does not throw warnings from token_get_all()'); } $errorHandler = new ErrorHandler\Collecting(); $lexer = $this->getLexer(['usedAttributes' => [ 'comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos' ]]); $lexer->startLexing($code, $errorHandler); $errors = $errorHandler->getErrors(); $this->assertCount(count($messages), $errors); for ($i = 0; $i < count($messages); $i++) { $this->assertSame($messages[$i], $errors[$i]->getMessageWithColumnInfo($code)); } } public function provideTestError() { return [ ["getLexer($options); $lexer->startLexing($code); while ($id = $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 [ // tests conversion of closing PHP tag and drop of whitespace and opening tags [ 'plaintext', [], [ [ Tokens::T_STRING, 'tokens', ['startLine' => 1], ['endLine' => 1] ], [ ord(';'), '?>', ['startLine' => 1], ['endLine' => 1] ], [ Tokens::T_INLINE_HTML, 'plaintext', ['startLine' => 1, 'hasLeadingNewline' => false], ['endLine' => 1] ], ] ], // tests line numbers [ ' 2], ['endLine' => 2] ], [ Tokens::T_STRING, 'token', ['startLine' => 2], ['endLine' => 2] ], [ ord('$'), '$', [ 'startLine' => 3, 'comments' => [ new Comment\Doc('/** doc' . "\n" . 'comment */', 2, 14, 5), ] ], ['endLine' => 3] ], ] ], // tests comment extraction [ ' 2, 'comments' => [ new Comment('/* comment */', 1, 6, 1), new Comment('// comment' . "\n", 1, 20, 3), new Comment\Doc('/** docComment 1 */', 2, 31, 4), new Comment\Doc('/** docComment 2 */', 2, 50, 5), ], ], ['endLine' => 2] ], ] ], // tests differing start and end line [ ' 1], ['endLine' => 2] ], ] ], // tests exact file offsets [ ' ['startFilePos', 'endFilePos']], [ [ Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"', ['startFilePos' => 6], ['endFilePos' => 8] ], [ ord(';'), ';', ['startFilePos' => 9], ['endFilePos' => 9] ], [ Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"', ['startFilePos' => 18], ['endFilePos' => 20] ], [ ord(';'), ';', ['startFilePos' => 21], ['endFilePos' => 21] ], ] ], // tests token offsets [ ' ['startTokenPos', 'endTokenPos']], [ [ Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"', ['startTokenPos' => 1], ['endTokenPos' => 1] ], [ ord(';'), ';', ['startTokenPos' => 2], ['endTokenPos' => 2] ], [ Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"', ['startTokenPos' => 5], ['endTokenPos' => 5] ], [ ord(';'), ';', ['startTokenPos' => 6], ['endTokenPos' => 6] ], ] ], // tests all attributes being disabled [ ' []], [ [ Tokens::T_VARIABLE, '$bar', [], [] ], [ ord(';'), ';', [], [] ] ] ], // tests no tokens [ '', [], [] ], ]; } /** * @dataProvider provideTestHaltCompiler */ public function testHandleHaltCompiler($code, $remaining) { $lexer = $this->getLexer(); $lexer->startLexing($code); while (Tokens::T_HALT_COMPILER !== $lexer->getNextToken()); $this->assertSame($remaining, $lexer->handleHaltCompiler()); $this->assertSame(0, $lexer->getNextToken()); } public function provideTestHaltCompiler() { return [ ['Remaining Text', 'Remaining Text'], //array('getLexer(); $lexer->startLexing('getNextToken()); $lexer->handleHaltCompiler(); } public function testGetTokens() { $code = 'getLexer(); $lexer->startLexing($code); $this->assertSame($expectedTokens, $lexer->getTokens()); } }