4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Tests\Caster;
14 use Symfony\Component\VarDumper\Test\VarDumperTestCase;
15 use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
16 use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
19 * @author Nicolas Grekas <p@tchwork.com>
21 class ReflectionCasterTest extends VarDumperTestCase
23 public function testReflectionCaster()
25 $var = new \ReflectionClass('ReflectionClass');
27 $this->assertDumpMatchesFormat(
30 +name: "ReflectionClass"
31 %Aimplements: array:%d [
35 "IS_IMPLICIT_ABSTRACT" => 16
36 "IS_EXPLICIT_ABSTRACT" => 32
39 properties: array:%d [
40 "name" => ReflectionProperty {
42 +class: "ReflectionClass"
43 %A modifiers: "public"
48 "export" => ReflectionMethod {
50 +class: "ReflectionClass"
52 $%s: ReflectionParameter {
61 public function testClosureCaster()
64 $var = function ($x) use ($a, &$b) {};
66 $this->assertDumpMatchesFormat(
76 file: "%sReflectionCasterTest.php"
84 public function testReflectionParameter()
86 $var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0);
88 $this->assertDumpMatchesFormat(
93 typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
104 public function testReflectionParameterScalar()
106 $f = eval('return function (int $a) {};');
107 $var = new \ReflectionParameter($f, 0);
109 $this->assertDumpMatchesFormat(
111 ReflectionParameter {
124 public function testReturnType()
126 $f = eval('return function ():int {};');
127 $line = __LINE__ - 1;
129 $this->assertDumpMatchesFormat(
133 class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
134 this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
135 file: "%sReflectionCasterTest.php($line) : eval()'d code"
146 public function testGenerator()
148 if (extension_loaded('xdebug')) {
149 $this->markTestSkipped('xdebug is active');
152 $generator = new GeneratorDemo();
153 $generator = $generator->baz();
155 $expectedDump = <<<'EODUMP'
157 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
159 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz(): {
160 %sGeneratorDemo.php:14: """
171 $this->assertDumpMatchesFormat($expectedDump, $generator);
173 foreach ($generator as $v) {
177 $expectedDump = <<<'EODUMP'
179 0 => ReflectionGenerator {
180 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
182 3. Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() ==> yield(): {
184 %sGeneratorDemo.php:9: """
191 2. Symfony\Component\VarDumper\Tests\Fixtures\bar() ==> Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo(): {
193 %sGeneratorDemo.php:20: """
195 yield from GeneratorDemo::foo();\n
200 1. Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() ==> Symfony\Component\VarDumper\Tests\Fixtures\bar(): {
202 %sGeneratorDemo.php:14: """
214 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo(): {
215 %sGeneratorDemo.php:10: """
227 $r = new \ReflectionGenerator($generator);
228 $this->assertDumpMatchesFormat($expectedDump, array($r, $r->getExecutingGenerator()));
230 foreach ($generator as $v) {
233 $expectedDump = <<<'EODUMP'
238 $this->assertDumpMatchesFormat($expectedDump, $generator);
242 function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)