[VarDumper] finish PHP 7.4 support and add tests
This commit is contained in:
parent
e99a6b85b8
commit
40f24ef676
|
@ -68,8 +68,8 @@ class Caster
|
||||||
foreach ($a as $k => $v) {
|
foreach ($a as $k => $v) {
|
||||||
if (isset($k[0]) ? "\0" !== $k[0] : \PHP_VERSION_ID >= 70200) {
|
if (isset($k[0]) ? "\0" !== $k[0] : \PHP_VERSION_ID >= 70200) {
|
||||||
if (!isset($publicProperties[$class])) {
|
if (!isset($publicProperties[$class])) {
|
||||||
foreach (get_class_vars($class) as $prop => $v) {
|
foreach ((new \ReflectionClass($class))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
|
||||||
$publicProperties[$class][$prop] = true;
|
$publicProperties[$class][$prop->name] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isset($publicProperties[$class][$k])) {
|
if (!isset($publicProperties[$class][$k])) {
|
||||||
|
|
|
@ -49,11 +49,17 @@ class Stub
|
||||||
$properties = [];
|
$properties = [];
|
||||||
|
|
||||||
if (!isset(self::$defaultProperties[$c = \get_class($this)])) {
|
if (!isset(self::$defaultProperties[$c = \get_class($this)])) {
|
||||||
self::$defaultProperties[$c] = get_class_vars($c);
|
$defaultProperties = get_class_vars($c);
|
||||||
|
|
||||||
foreach ((new \ReflectionClass($c))->getStaticProperties() as $k => $v) {
|
foreach ((new \ReflectionClass($c))->getProperties(\ReflectionProperty::IS_PUBLIC) as $v) {
|
||||||
unset(self::$defaultProperties[$c][$k]);
|
if ($v->isStatic()) {
|
||||||
|
unset($defaultProperties[$v->name]);
|
||||||
|
} elseif (!isset($defaultProperties[$v->name])) {
|
||||||
|
$defaultProperties[$v->name] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self::$defaultProperties[$c] = $defaultProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (self::$defaultProperties[$c] as $k => $v) {
|
foreach (self::$defaultProperties[$c] as $k => $v) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Component\VarDumper\Tests\Cloner;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||||
|
use Symfony\Component\VarDumper\Tests\Fixtures\Php74;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
@ -431,6 +432,73 @@ Symfony\Component\VarDumper\Cloner\Data Object
|
||||||
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
EOTXT;
|
||||||
|
$this->assertStringMatchesFormat($expected, print_r($clone, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.4
|
||||||
|
*/
|
||||||
|
public function testPhp74()
|
||||||
|
{
|
||||||
|
$data = new Php74();
|
||||||
|
|
||||||
|
$cloner = new VarCloner();
|
||||||
|
$clone = $cloner->cloneVar($data);
|
||||||
|
|
||||||
|
$expected = <<<'EOTXT'
|
||||||
|
Symfony\Component\VarDumper\Cloner\Data Object
|
||||||
|
(
|
||||||
|
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
|
||||||
|
(
|
||||||
|
[0] => Array
|
||||||
|
(
|
||||||
|
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||||
|
(
|
||||||
|
[type] => 4
|
||||||
|
[class] => Symfony\Component\VarDumper\Tests\Fixtures\Php74
|
||||||
|
[value] =>
|
||||||
|
[cut] => 0
|
||||||
|
[handle] => %i
|
||||||
|
[refCount] => 0
|
||||||
|
[position] => 1
|
||||||
|
[attr] => Array
|
||||||
|
(
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
[1] => Array
|
||||||
|
(
|
||||||
|
[p1] => 123
|
||||||
|
[p2] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||||
|
(
|
||||||
|
[type] => 4
|
||||||
|
[class] => stdClass
|
||||||
|
[value] =>
|
||||||
|
[cut] => 0
|
||||||
|
[handle] => %i
|
||||||
|
[refCount] => 0
|
||||||
|
[position] => 0
|
||||||
|
[attr] => Array
|
||||||
|
(
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
[position:Symfony\Component\VarDumper\Cloner\Data:private] => 0
|
||||||
|
[key:Symfony\Component\VarDumper\Cloner\Data:private] => 0
|
||||||
|
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
|
||||||
|
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||||
|
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||||
|
)
|
||||||
|
|
||||||
EOTXT;
|
EOTXT;
|
||||||
$this->assertStringMatchesFormat($expected, print_r($clone, true));
|
$this->assertStringMatchesFormat($expected, print_r($clone, true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\VarDumper\Tests\Fixtures;
|
||||||
|
|
||||||
|
class Php74
|
||||||
|
{
|
||||||
|
public $p1 = 123;
|
||||||
|
public \stdClass $p2;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->p2 = new \stdClass();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue