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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\VarDumper\Caster\Caster;
16 use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
17 use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
18 use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
21 * @author Nicolas Grekas <p@tchwork.com>
23 class ReflectionCasterTest extends TestCase
25 use VarDumperTestTrait;
27 public function testReflectionCaster()
29 $var = new \ReflectionClass('ReflectionClass');
31 $this->assertDumpMatchesFormat(
34 +name: "ReflectionClass"
35 %Aimplements: array:%d [
39 "IS_IMPLICIT_ABSTRACT" => 16
40 "IS_EXPLICIT_ABSTRACT" => 32
43 properties: array:%d [
44 "name" => ReflectionProperty {
46 +class: "ReflectionClass"
47 %A modifiers: "public"
52 "export" => ReflectionMethod {
54 +class: "ReflectionClass"
56 $%s: ReflectionParameter {
65 public function testClosureCaster()
68 $var = function ($x) use ($a, &$b) {};
70 $this->assertDumpMatchesFormat(
80 file: "%sReflectionCasterTest.php"
88 public function testClosureCasterExcludingVerbosity()
90 $var = function () {};
92 $expectedDump = <<<EOTXT
94 class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
95 this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
99 $this->assertDumpEquals($expectedDump, $var, Caster::EXCLUDE_VERBOSE);
102 public function testReflectionParameter()
104 $var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0);
106 $this->assertDumpMatchesFormat(
108 ReflectionParameter {
111 typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
122 public function testReflectionParameterScalar()
124 $f = eval('return function (int $a) {};');
125 $var = new \ReflectionParameter($f, 0);
127 $this->assertDumpMatchesFormat(
129 ReflectionParameter {
142 public function testReturnType()
144 $f = eval('return function ():int {};');
145 $line = __LINE__ - 1;
147 $this->assertDumpMatchesFormat(
151 class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
152 this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
153 file: "%sReflectionCasterTest.php($line) : eval()'d code"
164 public function testGenerator()
166 if (extension_loaded('xdebug')) {
167 $this->markTestSkipped('xdebug is active');
170 $generator = new GeneratorDemo();
171 $generator = $generator->baz();
173 $expectedDump = <<<'EODUMP'
175 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
177 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {
178 %sGeneratorDemo.php:14 {
189 $this->assertDumpMatchesFormat($expectedDump, $generator);
191 foreach ($generator as $v) {
195 $expectedDump = <<<'EODUMP'
197 0 => ReflectionGenerator {
198 this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
200 %s%eTests%eFixtures%eGeneratorDemo.php:9 {
205 %s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
206 %s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
212 Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() {
213 %sGeneratorDemo.php:10 {
225 $r = new \ReflectionGenerator($generator);
226 $this->assertDumpMatchesFormat($expectedDump, array($r, $r->getExecutingGenerator()));
228 foreach ($generator as $v) {
231 $expectedDump = <<<'EODUMP'
236 $this->assertDumpMatchesFormat($expectedDump, $generator);
240 function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)