PrettyPrinterTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. require_once dirname(__FILE__) . '/CodeTestAbstract.php';
  3. class PHPParser_Tests_PrettyPrinterTest extends PHPParser_Tests_CodeTestAbstract
  4. {
  5. protected function doTestPrettyPrintMethod($method, $name, $code, $dump) {
  6. $parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
  7. $prettyPrinter = new PHPParser_PrettyPrinter_Default;
  8. $stmts = $parser->parse($code);
  9. $this->assertEquals(
  10. $this->canonicalize($dump),
  11. $this->canonicalize($prettyPrinter->$method($stmts)),
  12. $name
  13. );
  14. }
  15. /**
  16. * @dataProvider provideTestPrettyPrint
  17. * @covers PHPParser_PrettyPrinter_Default<extended>
  18. */
  19. public function testPrettyPrint($name, $code, $dump) {
  20. $this->doTestPrettyPrintMethod('prettyPrint', $name, $code, $dump);
  21. }
  22. /**
  23. * @dataProvider provideTestPrettyPrintFile
  24. * @covers PHPParser_PrettyPrinter_Default<extended>
  25. */
  26. public function testPrettyPrintFile($name, $code, $dump) {
  27. $this->doTestPrettyPrintMethod('prettyPrintFile', $name, $code, $dump);
  28. }
  29. public function provideTestPrettyPrint() {
  30. return $this->getTests(dirname(__FILE__) . '/../../code/prettyPrinter', 'test');
  31. }
  32. public function provideTestPrettyPrintFile() {
  33. return $this->getTests(dirname(__FILE__) . '/../../code/prettyPrinter', 'file-test');
  34. }
  35. }