From 3c2f5f7a248fb8675e9d5259714eae388eb81e4d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 25 Jul 2017 16:01:38 +0200 Subject: [PATCH] [VarDumper] Adapt to php 7.2 changes --- .../Component/VarDumper/Caster/Caster.php | 2 +- .../VarDumper/Tests/CliDumperTest.php | 47 +++++++++++++++---- .../VarDumper/Tests/VarClonerTest.php | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index db052c8498..4123870043 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -54,7 +54,7 @@ class Caster if ($a) { $p = array_keys($a); 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) : \PHP_VERSION_ID >= 70200) { $p[$i] = self::PREFIX_DYNAMIC.$k; } elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) { $p[$i] = "\0".$reflector->getParentClass().'@anonymous'.strrchr($k, "\0"); diff --git a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php index f8acf0d562..ebf5eed35e 100644 --- a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php @@ -141,8 +141,22 @@ EOTXT $var[] = &$v; $var[''] = 2; - $this->assertDumpMatchesFormat( - <<<'EOTXT' + if (\PHP_VERSION_ID >= 70200) { + $this->assertDumpMatchesFormat( + <<<'EOTXT' +array:4 [ + 0 => {} + 1 => &1 null + 2 => &1 null + "" => 2 +] +EOTXT + , + $var + ); + } else { + $this->assertDumpMatchesFormat( + <<<'EOTXT' array:4 [ "0" => {} "1" => &1 null @@ -150,9 +164,10 @@ array:4 [ "" => 2 ] EOTXT - , - $var - ); + , + $var + ); + } } public function testObjectCast() @@ -160,16 +175,28 @@ EOTXT $var = (object) array(1 => 1); $var->{1} = 2; - $this->assertDumpMatchesFormat( - <<<'EOTXT' + if (\PHP_VERSION_ID >= 70200) { + $this->assertDumpMatchesFormat( + <<<'EOTXT' +{ + +"1": 2 +} +EOTXT + , + $var + ); + } else { + $this->assertDumpMatchesFormat( + <<<'EOTXT' { +1: 1 +"1": 2 } EOTXT - , - $var - ); + , + $var + ); + } } public function testClosedResource() diff --git a/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php b/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php index 8ca59bdddf..6e98d6ecbc 100644 --- a/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php +++ b/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php @@ -203,7 +203,7 @@ object(Symfony\Component\VarDumper\Cloner\Data)#%i (4) { EOTXT; ob_start(); var_dump($clone); - $this->assertStringMatchesFormat($expected, ob_get_clean()); + $this->assertStringMatchesFormat(\PHP_VERSION_ID >= 70200 ? str_replace('"1"', '1', $expected) : $expected, ob_get_clean()); } public function testCaster()