ParserTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. require_once dirname(__FILE__) . '/CodeTestAbstract.php';
  3. class PHPParser_Tests_ParserTest extends PHPParser_Tests_CodeTestAbstract
  4. {
  5. /**
  6. * @dataProvider provideTestParse
  7. */
  8. public function testParse($name, $code, $dump) {
  9. $parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
  10. $dumper = new PHPParser_NodeDumper;
  11. $stmts = $parser->parse($code);
  12. $this->assertEquals(
  13. $this->canonicalize($dump),
  14. $this->canonicalize($dumper->dump($stmts)),
  15. $name
  16. );
  17. }
  18. public function provideTestParse() {
  19. return $this->getTests(dirname(__FILE__) . '/../../code/parser', 'test');
  20. }
  21. /**
  22. * @dataProvider provideTestParseFail
  23. */
  24. public function testParseFail($name, $code, $msg) {
  25. $parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
  26. try {
  27. $parser->parse($code);
  28. $this->fail(sprintf('"%s": Expected PHPParser_Error', $name));
  29. } catch (PHPParser_Error $e) {
  30. $this->assertEquals($msg, $e->getMessage(), $name);
  31. }
  32. }
  33. public function provideTestParseFail() {
  34. return $this->getTests(dirname(__FILE__) . '/../../code/parser', 'test-fail');
  35. }
  36. }