2011-07-13 23:07:05 +02:00
|
|
|
<?php
|
|
|
|
|
2011-08-10 11:13:37 +02:00
|
|
|
class PHPParser_Tests_NodeDumperTest extends PHPUnit_Framework_TestCase
|
2011-07-13 23:07:05 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideTestDump
|
2011-11-27 12:53:48 +01:00
|
|
|
* @covers PHPParser_NodeDumper::dump
|
2011-07-13 23:07:05 +02:00
|
|
|
*/
|
|
|
|
public function testDump($node, $dump) {
|
2011-11-27 21:43:27 +01:00
|
|
|
$dumper = new PHPParser_NodeDumper;
|
2011-07-13 23:07:05 +02:00
|
|
|
|
2011-11-27 21:43:27 +01:00
|
|
|
$this->assertEquals($dump, $dumper->dump($node));
|
2011-07-13 23:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideTestDump() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(),
|
|
|
|
'array(
|
|
|
|
)'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('Foo', 'Bar', 'Key' => 'FooBar'),
|
|
|
|
'array(
|
|
|
|
0: Foo
|
|
|
|
1: Bar
|
|
|
|
Key: FooBar
|
|
|
|
)'
|
|
|
|
),
|
|
|
|
array(
|
2011-08-09 14:55:45 +02:00
|
|
|
new PHPParser_Node_Name(array('Hallo', 'World')),
|
2011-07-13 23:07:05 +02:00
|
|
|
'Name(
|
|
|
|
parts: array(
|
|
|
|
0: Hallo
|
|
|
|
1: World
|
|
|
|
)
|
|
|
|
)'
|
|
|
|
),
|
|
|
|
array(
|
2011-08-11 08:13:01 +02:00
|
|
|
new PHPParser_Node_Expr_Array(array(
|
2011-09-02 19:49:46 +02:00
|
|
|
new PHPParser_Node_Expr_ArrayItem(new PHPParser_Node_Scalar_String('Foo'))
|
2011-08-11 08:13:01 +02:00
|
|
|
)),
|
2011-07-13 23:07:05 +02:00
|
|
|
'Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
2011-08-11 08:13:01 +02:00
|
|
|
key: null
|
|
|
|
value: Scalar_String(
|
|
|
|
value: Foo
|
|
|
|
)
|
2011-07-13 23:07:05 +02:00
|
|
|
byRef: false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
* @expectedExceptionMessage Can only dump nodes and arrays.
|
|
|
|
*/
|
|
|
|
public function testError() {
|
|
|
|
$dumper = new PHPParser_NodeDumper;
|
|
|
|
$dumper->dump(new stdClass);
|
|
|
|
}
|
2011-07-13 23:07:05 +02:00
|
|
|
}
|