[VarDumper] Fix casting for ReflectionParameter
This commit is contained in:
parent
c24ca431ff
commit
8ff449d86c
@ -157,6 +157,9 @@ class ReflectionCaster
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
// Added by HHVM
|
||||
unset($a['info']);
|
||||
|
||||
self::addMap($a, $c, array(
|
||||
'position' => 'getPosition',
|
||||
'isVariadic' => 'isVariadic',
|
||||
@ -172,6 +175,9 @@ class ReflectionCaster
|
||||
$a[$prefix.'typeHint'] = $v->name;
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
|
||||
$a[$prefix.'typeHint'] = $m[1];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@ -180,6 +186,9 @@ class ReflectionCaster
|
||||
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
if (isset($a[$prefix.'typeHint']) && $c->allowsNull()) {
|
||||
$a[$prefix.'default'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $a;
|
||||
|
@ -61,6 +61,23 @@ EOTXT
|
||||
);
|
||||
}
|
||||
|
||||
public function testReflectionParameter()
|
||||
{
|
||||
$var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0);
|
||||
|
||||
$this->assertDumpMatchesFormat(
|
||||
<<<'EOTXT'
|
||||
ReflectionParameter {
|
||||
+name: "arg1"
|
||||
position: 0
|
||||
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
|
||||
default: null
|
||||
}
|
||||
EOTXT
|
||||
, $var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
@ -74,7 +91,7 @@ Closure {
|
||||
returnType: "int"
|
||||
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
|
||||
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
|
||||
file: "%sReflectionCasterTest.php(69) : eval()'d code"
|
||||
file: "%sReflectionCasterTest.php(86) : eval()'d code"
|
||||
line: "1 to 1"
|
||||
}
|
||||
EOTXT
|
||||
@ -82,3 +99,7 @@ EOTXT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
|
||||
{
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
// Skipping trait tests for PHP < 5.4
|
||||
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
|
||||
require 'VarDumpTestTraitRequire54.php';
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
require __DIR__.'/VarDumperTestTraitRequire54.php';
|
||||
}
|
||||
|
Reference in New Issue
Block a user