2011-11-06 18:09:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PHPParser_Tests_Serializer_XMLTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2011-11-27 12:53:48 +01:00
|
|
|
/**
|
|
|
|
* @covers PHPParser_Serializer_XML<extended>
|
|
|
|
*/
|
2011-11-06 18:09:32 +01:00
|
|
|
public function testSerialize() {
|
2011-12-18 13:04:27 +01:00
|
|
|
$code = <<<CODE
|
2011-11-06 18:09:32 +01:00
|
|
|
<?php
|
2011-11-27 21:43:27 +01:00
|
|
|
/** doc comment */
|
2011-12-18 13:04:27 +01:00
|
|
|
function functionName(&\$a = 0, \$b = 1.0) {
|
2011-11-27 21:43:27 +01:00
|
|
|
echo 'Foo';
|
2011-11-06 18:09:32 +01:00
|
|
|
}
|
|
|
|
CODE;
|
2011-11-27 21:43:27 +01:00
|
|
|
$xml = <<<XML
|
2011-11-06 18:09:32 +01:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar">
|
2011-11-27 21:43:27 +01:00
|
|
|
<scalar:array>
|
|
|
|
<node:Stmt_Function line="3" docComment="/** doc comment */">
|
2011-11-06 18:09:32 +01:00
|
|
|
<subNode:byRef>
|
2011-11-27 21:43:27 +01:00
|
|
|
<scalar:false/>
|
2011-11-06 18:09:32 +01:00
|
|
|
</subNode:byRef>
|
2011-11-27 21:43:27 +01:00
|
|
|
<subNode:params>
|
|
|
|
<scalar:array>
|
|
|
|
<node:Param line="3">
|
|
|
|
<subNode:name>
|
|
|
|
<scalar:string>a</scalar:string>
|
|
|
|
</subNode:name>
|
|
|
|
<subNode:default>
|
|
|
|
<node:Scalar_LNumber line="3">
|
|
|
|
<subNode:value>
|
|
|
|
<scalar:int>0</scalar:int>
|
|
|
|
</subNode:value>
|
|
|
|
</node:Scalar_LNumber>
|
|
|
|
</subNode:default>
|
|
|
|
<subNode:type>
|
|
|
|
<scalar:null/>
|
|
|
|
</subNode:type>
|
|
|
|
<subNode:byRef>
|
|
|
|
<scalar:true/>
|
|
|
|
</subNode:byRef>
|
|
|
|
</node:Param>
|
|
|
|
<node:Param line="3">
|
|
|
|
<subNode:name>
|
|
|
|
<scalar:string>b</scalar:string>
|
|
|
|
</subNode:name>
|
|
|
|
<subNode:default>
|
|
|
|
<node:Scalar_DNumber line="3">
|
|
|
|
<subNode:value>
|
|
|
|
<scalar:float>1</scalar:float>
|
|
|
|
</subNode:value>
|
|
|
|
</node:Scalar_DNumber>
|
|
|
|
</subNode:default>
|
|
|
|
<subNode:type>
|
|
|
|
<scalar:null/>
|
|
|
|
</subNode:type>
|
|
|
|
<subNode:byRef>
|
|
|
|
<scalar:false/>
|
|
|
|
</subNode:byRef>
|
|
|
|
</node:Param>
|
|
|
|
</scalar:array>
|
|
|
|
</subNode:params>
|
|
|
|
<subNode:stmts>
|
|
|
|
<scalar:array>
|
|
|
|
<node:Stmt_Echo line="4">
|
|
|
|
<subNode:exprs>
|
|
|
|
<scalar:array>
|
|
|
|
<node:Scalar_String line="4">
|
|
|
|
<subNode:value>
|
|
|
|
<scalar:string>Foo</scalar:string>
|
|
|
|
</subNode:value>
|
|
|
|
</node:Scalar_String>
|
|
|
|
</scalar:array>
|
|
|
|
</subNode:exprs>
|
|
|
|
</node:Stmt_Echo>
|
|
|
|
</scalar:array>
|
|
|
|
</subNode:stmts>
|
|
|
|
<subNode:name>
|
|
|
|
<scalar:string>functionName</scalar:string>
|
|
|
|
</subNode:name>
|
|
|
|
</node:Stmt_Function>
|
|
|
|
</scalar:array>
|
2011-11-06 18:09:32 +01:00
|
|
|
</AST>
|
|
|
|
XML;
|
|
|
|
|
2012-04-25 20:04:46 +02:00
|
|
|
$parser = new PHPParser_Parser(new PHPParser_Lexer);
|
2011-11-06 18:09:32 +01:00
|
|
|
$serializer = new PHPParser_Serializer_XML;
|
|
|
|
|
2012-04-25 20:04:46 +02:00
|
|
|
$stmts = $parser->parse($code);
|
2011-11-06 18:09:32 +01:00
|
|
|
$this->assertXmlStringEqualsXmlString($xml, $serializer->serialize($stmts));
|
|
|
|
}
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
* @expectedExceptionMessage Unexpected node type
|
|
|
|
*/
|
|
|
|
public function testError() {
|
|
|
|
$serializer = new PHPParser_Serializer_XML;
|
|
|
|
$serializer->serialize(array(new stdClass));
|
|
|
|
}
|
2011-11-06 18:09:32 +01:00
|
|
|
}
|