8000 [VarDumper] Fix casting for ReflectionParameter · symfony/symfony@8ff449d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ff449d

Browse files
[VarDumper] Fix casting for ReflectionParameter
1 parent c24ca43 commit 8ff449d

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
157157
{
158158
$prefix = Caster::PREFIX_VIRTUAL;
159159

160+
// Added by HHVM
161+
unset($a['info']);
162+
160163
self::addMap($a, $c, array(
161164
'position' => 'getPosition',
162165
'isVariadic' => 'isVariadic',
@@ -172,6 +175,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
172175
$a[$prefix.'typeHint'] = $v->name;
173176
}
174177
} catch (\ReflectionException $e) {
178+
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
179+
$a[$prefix.'typeHint'] = $m[1];
180+
}
175181
}
176182

177183
try {
@@ -180,6 +186,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
180186
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
181187
}
182188
} catch (\ReflectionException $e) {
189+
if (isset($a[$prefix.'typeHint']) && $c->allowsNull()) {
190+
$a[$prefix.'default'] = null;
191+
}
183192
}
184193

185194
return $a;

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ public function testReflectionCaster()
6161
);
6262
}
6363

64+
public function testReflectionParameter()
65+
{
66+
$var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0);
67+
68+
$this->assertDumpMatchesFormat(
69+
<<<'EOTXT'
70+
ReflectionParameter {
71+
+name: "arg1"
72+
position: 0
73+
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
74+
default: null
75+
}
76+
EOTXT
77+
, $var
78+
);
79+
}
80+
6481
/**
6582
* @requires PHP 7.0
6683
*/
@@ -74,11 +91,15 @@ public function testReturnType()
7491
returnType: "int"
7592
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
7693
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
77-
file: "%sReflectionCasterTest.php(69) : eval()'d code"
94+
file: "%sReflectionCasterTest.php(86) : eval()'d code"
7895
line: "1 to 1"
7996
}
8097
EOTXT
8198
, $f
8299
);
83100
}
84101
}
102+
103+
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
104+
{
105+
}

src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php renamed to src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
// Skipping trait tests for PHP < 5.4
13-
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
14-
require 'VarDumpTestTraitRequire54.php';
13+
if (PHP_VERSION_ID >= 50400) {
14+
require __DIR__.'/VarDumperTestTraitRequire54.php';
1515
}
1616

0 commit comments

Comments
 (0)
0