Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/Serializer/XMLTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace PhpParser\Serializer; | |
4 | |
5 use PhpParser; | |
6 | |
7 class XMLTest extends \PHPUnit_Framework_TestCase | |
8 { | |
9 /** | |
10 * @covers PhpParser\Serializer\XML<extended> | |
11 */ | |
12 public function testSerialize() { | |
13 $code = <<<CODE | |
14 <?php | |
15 // comment | |
16 /** doc comment */ | |
17 function functionName(&\$a = 0, \$b = 1.0) { | |
18 echo 'Foo'; | |
19 } | |
20 CODE; | |
21 $xml = <<<XML | |
22 <?xml version="1.0" encoding="UTF-8"?> | |
23 <AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:attribute="http://nikic.github.com/PHPParser/XML/attribute" xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar"> | |
24 <scalar:array> | |
25 <node:Stmt_Function> | |
26 <attribute:startLine> | |
27 <scalar:int>4</scalar:int> | |
28 </attribute:startLine> | |
29 <attribute:comments> | |
30 <scalar:array> | |
31 <comment isDocComment="false" line="2">// comment | |
32 </comment> | |
33 <comment isDocComment="true" line="3">/** doc comment */</comment> | |
34 </scalar:array> | |
35 </attribute:comments> | |
36 <attribute:endLine> | |
37 <scalar:int>6</scalar:int> | |
38 </attribute:endLine> | |
39 <subNode:byRef> | |
40 <scalar:false/> | |
41 </subNode:byRef> | |
42 <subNode:name> | |
43 <scalar:string>functionName</scalar:string> | |
44 </subNode:name> | |
45 <subNode:params> | |
46 <scalar:array> | |
47 <node:Param> | |
48 <attribute:startLine> | |
49 <scalar:int>4</scalar:int> | |
50 </attribute:startLine> | |
51 <attribute:endLine> | |
52 <scalar:int>4</scalar:int> | |
53 </attribute:endLine> | |
54 <subNode:type> | |
55 <scalar:null/> | |
56 </subNode:type> | |
57 <subNode:byRef> | |
58 <scalar:true/> | |
59 </subNode:byRef> | |
60 <subNode:variadic> | |
61 <scalar:false/> | |
62 </subNode:variadic> | |
63 <subNode:name> | |
64 <scalar:string>a</scalar:string> | |
65 </subNode:name> | |
66 <subNode:default> | |
67 <node:Scalar_LNumber> | |
68 <attribute:startLine> | |
69 <scalar:int>4</scalar:int> | |
70 </attribute:startLine> | |
71 <attribute:endLine> | |
72 <scalar:int>4</scalar:int> | |
73 </attribute:endLine> | |
74 <attribute:kind> | |
75 <scalar:int>10</scalar:int> | |
76 </attribute:kind> | |
77 <subNode:value> | |
78 <scalar:int>0</scalar:int> | |
79 </subNode:value> | |
80 </node:Scalar_LNumber> | |
81 </subNode:default> | |
82 </node:Param> | |
83 <node:Param> | |
84 <attribute:startLine> | |
85 <scalar:int>4</scalar:int> | |
86 </attribute:startLine> | |
87 <attribute:endLine> | |
88 <scalar:int>4</scalar:int> | |
89 </attribute:endLine> | |
90 <subNode:type> | |
91 <scalar:null/> | |
92 </subNode:type> | |
93 <subNode:byRef> | |
94 <scalar:false/> | |
95 </subNode:byRef> | |
96 <subNode:variadic> | |
97 <scalar:false/> | |
98 </subNode:variadic> | |
99 <subNode:name> | |
100 <scalar:string>b</scalar:string> | |
101 </subNode:name> | |
102 <subNode:default> | |
103 <node:Scalar_DNumber> | |
104 <attribute:startLine> | |
105 <scalar:int>4</scalar:int> | |
106 </attribute:startLine> | |
107 <attribute:endLine> | |
108 <scalar:int>4</scalar:int> | |
109 </attribute:endLine> | |
110 <subNode:value> | |
111 <scalar:float>1</scalar:float> | |
112 </subNode:value> | |
113 </node:Scalar_DNumber> | |
114 </subNode:default> | |
115 </node:Param> | |
116 </scalar:array> | |
117 </subNode:params> | |
118 <subNode:returnType> | |
119 <scalar:null/> | |
120 </subNode:returnType> | |
121 <subNode:stmts> | |
122 <scalar:array> | |
123 <node:Stmt_Echo> | |
124 <attribute:startLine> | |
125 <scalar:int>5</scalar:int> | |
126 </attribute:startLine> | |
127 <attribute:endLine> | |
128 <scalar:int>5</scalar:int> | |
129 </attribute:endLine> | |
130 <subNode:exprs> | |
131 <scalar:array> | |
132 <node:Scalar_String> | |
133 <attribute:startLine> | |
134 <scalar:int>5</scalar:int> | |
135 </attribute:startLine> | |
136 <attribute:endLine> | |
137 <scalar:int>5</scalar:int> | |
138 </attribute:endLine> | |
139 <attribute:kind> | |
140 <scalar:int>1</scalar:int> | |
141 </attribute:kind> | |
142 <subNode:value> | |
143 <scalar:string>Foo</scalar:string> | |
144 </subNode:value> | |
145 </node:Scalar_String> | |
146 </scalar:array> | |
147 </subNode:exprs> | |
148 </node:Stmt_Echo> | |
149 </scalar:array> | |
150 </subNode:stmts> | |
151 </node:Stmt_Function> | |
152 </scalar:array> | |
153 </AST> | |
154 XML; | |
155 | |
156 $parser = new PhpParser\Parser\Php7(new PhpParser\Lexer); | |
157 $serializer = new XML; | |
158 | |
159 $code = str_replace("\r\n", "\n", $code); | |
160 $stmts = $parser->parse($code); | |
161 $this->assertXmlStringEqualsXmlString($xml, $serializer->serialize($stmts)); | |
162 } | |
163 | |
164 /** | |
165 * @expectedException \InvalidArgumentException | |
166 * @expectedExceptionMessage Unexpected node type | |
167 */ | |
168 public function testError() { | |
169 $serializer = new XML; | |
170 $serializer->serialize(array(new \stdClass)); | |
171 } | |
172 } |