[VarDumper] Fix PHP7 type-hints compat

This commit is contained in:
Nicolas Grekas 2015-11-06 09:22:03 +01:00
parent 1bed1772f6
commit edd5633374
2 changed files with 29 additions and 4 deletions

View File

@ -167,7 +167,11 @@ class ReflectionCaster
));
try {
if ($c->isArray()) {
if (method_exists($c, 'hasType')) {
if ($c->hasType()) {
$a[$prefix.'typeHint'] = $c->getType()->__toString();
}
} elseif ($c->isArray()) {
$a[$prefix.'typeHint'] = 'array';
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
$a[$prefix.'typeHint'] = 'callable';

View File

@ -81,17 +81,38 @@ EOTXT
/**
* @requires PHP 7.0
*/
public function testReturnType()
public function testReflectionParameterScalar()
{
$f = eval('return function ():int {};');
$f = eval('return function (int $a) {};');
$var = new \ReflectionParameter($f, 0);
$this->assertDumpMatchesFormat(
<<<'EOTXT'
ReflectionParameter {
+name: "a"
position: 0
typeHint: "int"
}
EOTXT
, $var
);
}
/**
* @requires PHP 7.0
*/
public function testReturnType()
{
$f = eval('return function ():int {};');
$line = __LINE__ - 1;
$this->assertDumpMatchesFormat(
<<<EOTXT
Closure {
returnType: "int"
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { }
file: "%sReflectionCasterTest.php(86) : eval()'d code"
file: "%sReflectionCasterTest.php($line) : eval()'d code"
line: "1 to 1"
}
EOTXT