NodeDumperTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class PHPParser_Tests_NodeDumperTest extends PHPUnit_Framework_TestCase
  3. {
  4. /**
  5. * @dataProvider provideTestDump
  6. * @covers PHPParser_NodeDumper::dump
  7. */
  8. public function testDump($node, $dump) {
  9. $dumper = new PHPParser_NodeDumper;
  10. $this->assertEquals($dump, $dumper->dump($node));
  11. }
  12. public function provideTestDump() {
  13. return array(
  14. array(
  15. array(),
  16. 'array(
  17. )'
  18. ),
  19. array(
  20. array('Foo', 'Bar', 'Key' => 'FooBar'),
  21. 'array(
  22. 0: Foo
  23. 1: Bar
  24. Key: FooBar
  25. )'
  26. ),
  27. array(
  28. new PHPParser_Node_Name(array('Hallo', 'World')),
  29. 'Name(
  30. parts: array(
  31. 0: Hallo
  32. 1: World
  33. )
  34. )'
  35. ),
  36. array(
  37. new PHPParser_Node_Expr_Array(array(
  38. new PHPParser_Node_Expr_ArrayItem(new PHPParser_Node_Scalar_String('Foo'))
  39. )),
  40. 'Expr_Array(
  41. items: array(
  42. 0: Expr_ArrayItem(
  43. key: null
  44. value: Scalar_String(
  45. value: Foo
  46. )
  47. byRef: false
  48. )
  49. )
  50. )'
  51. ),
  52. );
  53. }
  54. /**
  55. * @expectedException InvalidArgumentException
  56. * @expectedExceptionMessage Can only dump nodes and arrays.
  57. */
  58. public function testError() {
  59. $dumper = new PHPParser_NodeDumper;
  60. $dumper->dump(new stdClass);
  61. }
  62. }