Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Tests/Caster/ReflectionCasterTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\VarDumper\Tests\Caster; | |
13 | |
14 use PHPUnit\Framework\TestCase; | |
15 use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | |
16 use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo; | |
17 use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass; | |
18 | |
19 /** | |
20 * @author Nicolas Grekas <p@tchwork.com> | |
21 */ | |
22 class ReflectionCasterTest extends TestCase | |
23 { | |
24 use VarDumperTestTrait; | |
25 | |
26 public function testReflectionCaster() | |
27 { | |
28 $var = new \ReflectionClass('ReflectionClass'); | |
29 | |
30 $this->assertDumpMatchesFormat( | |
31 <<<'EOTXT' | |
32 ReflectionClass { | |
33 +name: "ReflectionClass" | |
34 %Aimplements: array:%d [ | |
35 0 => "Reflector" | |
36 %A] | |
37 constants: array:3 [ | |
38 "IS_IMPLICIT_ABSTRACT" => 16 | |
39 "IS_EXPLICIT_ABSTRACT" => 32 | |
40 "IS_FINAL" => %d | |
41 ] | |
42 properties: array:%d [ | |
43 "name" => ReflectionProperty { | |
44 %A +name: "name" | |
45 +class: "ReflectionClass" | |
46 %A modifiers: "public" | |
47 } | |
48 %A] | |
49 methods: array:%d [ | |
50 %A | |
51 "export" => ReflectionMethod { | |
52 +name: "export" | |
53 +class: "ReflectionClass" | |
54 %A parameters: { | |
55 $%s: ReflectionParameter { | |
56 %A position: 0 | |
57 %A | |
58 } | |
59 EOTXT | |
60 , $var | |
61 ); | |
62 } | |
63 | |
64 public function testClosureCaster() | |
65 { | |
66 $a = $b = 123; | |
67 $var = function ($x) use ($a, &$b) {}; | |
68 | |
69 $this->assertDumpMatchesFormat( | |
70 <<<EOTXT | |
71 Closure { | |
72 %Aparameters: { | |
73 \$x: {} | |
74 } | |
75 use: { | |
76 \$a: 123 | |
77 \$b: & 123 | |
78 } | |
79 file: "%sReflectionCasterTest.php" | |
80 line: "67 to 67" | |
81 } | |
82 EOTXT | |
83 , $var | |
84 ); | |
85 } | |
86 | |
87 public function testReflectionParameter() | |
88 { | |
89 $var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0); | |
90 | |
91 $this->assertDumpMatchesFormat( | |
92 <<<'EOTXT' | |
93 ReflectionParameter { | |
94 +name: "arg1" | |
95 position: 0 | |
96 typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass" | |
97 default: null | |
98 } | |
99 EOTXT | |
100 , $var | |
101 ); | |
102 } | |
103 | |
104 /** | |
105 * @requires PHP 7.0 | |
106 */ | |
107 public function testReflectionParameterScalar() | |
108 { | |
109 $f = eval('return function (int $a) {};'); | |
110 $var = new \ReflectionParameter($f, 0); | |
111 | |
112 $this->assertDumpMatchesFormat( | |
113 <<<'EOTXT' | |
114 ReflectionParameter { | |
115 +name: "a" | |
116 position: 0 | |
117 typeHint: "int" | |
118 } | |
119 EOTXT | |
120 , $var | |
121 ); | |
122 } | |
123 | |
124 /** | |
125 * @requires PHP 7.0 | |
126 */ | |
127 public function testReturnType() | |
128 { | |
129 $f = eval('return function ():int {};'); | |
130 $line = __LINE__ - 1; | |
131 | |
132 $this->assertDumpMatchesFormat( | |
133 <<<EOTXT | |
134 Closure { | |
135 returnType: "int" | |
136 class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest" | |
137 this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …} | |
138 file: "%sReflectionCasterTest.php($line) : eval()'d code" | |
139 line: "1 to 1" | |
140 } | |
141 EOTXT | |
142 , $f | |
143 ); | |
144 } | |
145 | |
146 /** | |
147 * @requires PHP 7.0 | |
148 */ | |
149 public function testGenerator() | |
150 { | |
151 if (extension_loaded('xdebug')) { | |
152 $this->markTestSkipped('xdebug is active'); | |
153 } | |
154 | |
155 $generator = new GeneratorDemo(); | |
156 $generator = $generator->baz(); | |
157 | |
158 $expectedDump = <<<'EODUMP' | |
159 Generator { | |
160 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …} | |
161 executing: { | |
162 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz(): { | |
163 %sGeneratorDemo.php:14: { | |
164 : { | |
165 : yield from bar(); | |
166 : } | |
167 } | |
168 } | |
169 } | |
170 closed: false | |
171 } | |
172 EODUMP; | |
173 | |
174 $this->assertDumpMatchesFormat($expectedDump, $generator); | |
175 | |
176 foreach ($generator as $v) { | |
177 break; | |
178 } | |
179 | |
180 $expectedDump = <<<'EODUMP' | |
181 array:2 [ | |
182 0 => ReflectionGenerator { | |
183 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …} | |
184 trace: { | |
185 %sGeneratorDemo.php:9: { | |
186 : { | |
187 : yield 1; | |
188 : } | |
189 } | |
190 %sGeneratorDemo.php:20: { | |
191 : { | |
192 : yield from GeneratorDemo::foo(); | |
193 : } | |
194 } | |
195 %sGeneratorDemo.php:14: { | |
196 : { | |
197 : yield from bar(); | |
198 : } | |
199 } | |
200 } | |
201 closed: false | |
202 } | |
203 1 => Generator { | |
204 executing: { | |
205 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo(): { | |
206 %sGeneratorDemo.php:10: { | |
207 : yield 1; | |
208 : } | |
209 : | |
210 } | |
211 } | |
212 } | |
213 closed: false | |
214 } | |
215 ] | |
216 EODUMP; | |
217 | |
218 $r = new \ReflectionGenerator($generator); | |
219 $this->assertDumpMatchesFormat($expectedDump, array($r, $r->getExecutingGenerator())); | |
220 | |
221 foreach ($generator as $v) { | |
222 } | |
223 | |
224 $expectedDump = <<<'EODUMP' | |
225 Generator { | |
226 closed: true | |
227 } | |
228 EODUMP; | |
229 $this->assertDumpMatchesFormat($expectedDump, $generator); | |
230 } | |
231 } | |
232 | |
233 function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2) | |
234 { | |
235 } |