[VarDumper] Fix return type and anonymous classes dumping
This commit is contained in:
parent
80182faf0f
commit
b42b03a62b
@ -54,6 +54,8 @@ class Caster
|
|||||||
foreach ($p as $i => $k) {
|
foreach ($p as $i => $k) {
|
||||||
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
|
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
|
||||||
$p[$i] = self::PREFIX_DYNAMIC.$k;
|
$p[$i] = self::PREFIX_DYNAMIC.$k;
|
||||||
|
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
|
||||||
|
$p[$i] = "\0anonymous-".$reflector->name.strrchr($k, "\0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$a = array_combine($p, $a);
|
$a = array_combine($p, $a);
|
||||||
|
@ -114,6 +114,9 @@ class ReflectionCaster
|
|||||||
'this' => 'getClosureThis',
|
'this' => 'getClosureThis',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if (isset($a[$prefix.'returnType'])) {
|
||||||
|
$a[$prefix.'returnType'] = (string) $a[$prefix.'returnType'];
|
||||||
|
}
|
||||||
if (isset($a[$prefix.'this'])) {
|
if (isset($a[$prefix.'this'])) {
|
||||||
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
||||||
}
|
}
|
||||||
|
@ -208,9 +208,12 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
$obj = $stub->value;
|
$obj = $stub->value;
|
||||||
$class = $stub->class;
|
$class = $stub->class;
|
||||||
|
|
||||||
|
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
|
||||||
|
$class = get_parent_class($class);
|
||||||
|
$stub->class = 'anonymous-'.$class;
|
||||||
|
}
|
||||||
if (isset($this->classInfo[$class])) {
|
if (isset($this->classInfo[$class])) {
|
||||||
$classInfo = $this->classInfo[$class];
|
$classInfo = $this->classInfo[$class];
|
||||||
$stub->class = $classInfo[0];
|
|
||||||
} else {
|
} else {
|
||||||
$classInfo = array(
|
$classInfo = array(
|
||||||
$class,
|
$class,
|
||||||
|
@ -12,11 +12,12 @@
|
|||||||
namespace Symfony\Component\VarDumper\Tests\Caster;
|
namespace Symfony\Component\VarDumper\Tests\Caster;
|
||||||
|
|
||||||
use Symfony\Component\VarDumper\Caster\Caster;
|
use Symfony\Component\VarDumper\Caster\Caster;
|
||||||
|
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
*/
|
*/
|
||||||
class CasterTest extends \PHPUnit_Framework_TestCase
|
class CasterTest extends VarDumperTestCase
|
||||||
{
|
{
|
||||||
private $referenceArray = array(
|
private $referenceArray = array(
|
||||||
'null' => null,
|
'null' => null,
|
||||||
@ -28,7 +29,9 @@ class CasterTest extends \PHPUnit_Framework_TestCase
|
|||||||
"\0Foo\0private" => 'priv',
|
"\0Foo\0private" => 'priv',
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @dataProvider provideFilter */
|
/**
|
||||||
|
* @dataProvider provideFilter
|
||||||
|
*/
|
||||||
public function testFilter($filter, $expectedDiff, $listedProperties = null)
|
public function testFilter($filter, $expectedDiff, $listedProperties = null)
|
||||||
{
|
{
|
||||||
if (null === $listedProperties) {
|
if (null === $listedProperties) {
|
||||||
@ -144,4 +147,21 @@ class CasterTest extends \PHPUnit_Framework_TestCase
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.0
|
||||||
|
*/
|
||||||
|
public function testAnonymousClass()
|
||||||
|
{
|
||||||
|
$c = eval('return new class extends stdClass { private $foo = "foo"; };');
|
||||||
|
|
||||||
|
$this->assertDumpMatchesFormat(
|
||||||
|
<<<'EOTXT'
|
||||||
|
anonymous-stdClass {
|
||||||
|
-foo: "foo"
|
||||||
|
}
|
||||||
|
EOTXT
|
||||||
|
, $c
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,25 @@ EOTXT
|
|||||||
, $var
|
, $var
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.0
|
||||||
|
*/
|
||||||
|
public function testReturnType()
|
||||||
|
{
|
||||||
|
$f = eval('return function ():int {};');
|
||||||
|
|
||||||
|
$this->assertDumpMatchesFormat(
|
||||||
|
<<<'EOTXT'
|
||||||
|
Closure {
|
||||||
|
returnType: "int"
|
||||||
|
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
|
||||||
|
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
|
||||||
|
file: "%sReflectionCasterTest.php(69) : eval()'d code"
|
||||||
|
line: "1 to 1"
|
||||||
|
}
|
||||||
|
EOTXT
|
||||||
|
, $f
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user