2011-07-13 23:07:05 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser;
|
|
|
|
|
|
|
|
class NodeDumperTest extends \PHPUnit_Framework_TestCase
|
2011-07-13 23:07:05 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideTestDump
|
2014-09-28 12:48:55 +02:00
|
|
|
* @covers PhpParser\NodeDumper::dump
|
2011-07-13 23:07:05 +02:00
|
|
|
*/
|
|
|
|
public function testDump($node, $dump) {
|
2014-02-06 14:44:16 +01:00
|
|
|
$dumper = new NodeDumper;
|
2011-07-13 23:07:05 +02:00
|
|
|
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame($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(
|
2014-02-06 14:44:16 +01:00
|
|
|
new Node\Name(array('Hallo', 'World')),
|
2011-07-13 23:07:05 +02:00
|
|
|
'Name(
|
|
|
|
parts: array(
|
|
|
|
0: Hallo
|
|
|
|
1: World
|
|
|
|
)
|
|
|
|
)'
|
|
|
|
),
|
|
|
|
array(
|
2014-02-06 14:44:16 +01:00
|
|
|
new Node\Expr\Array_(array(
|
|
|
|
new Node\Expr\ArrayItem(new 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
|
|
|
|
|
|
|
/**
|
2014-02-06 14:44:16 +01:00
|
|
|
* @expectedException \InvalidArgumentException
|
2011-11-27 21:43:27 +01:00
|
|
|
* @expectedExceptionMessage Can only dump nodes and arrays.
|
|
|
|
*/
|
|
|
|
public function testError() {
|
2014-02-06 14:44:16 +01:00
|
|
|
$dumper = new NodeDumper;
|
|
|
|
$dumper->dump(new \stdClass);
|
2011-11-27 21:43:27 +01:00
|
|
|
}
|
2011-07-13 23:07:05 +02:00
|
|
|
}
|