Skip to content

Commit

Permalink
[VarDumper] Add tests to demonstrate a bug when dumping ArrayObject w…
Browse files Browse the repository at this point in the history
…ith full stack fmk
  • Loading branch information
lyrixx authored and HypeMC committed Jul 12, 2023
1 parent 4684507 commit 4e90aa3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Tests/Integration/dump_data_collector.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
Test integration with Symfony's DumpDataCollector
--FILE--
<?php
putenv('NO_COLOR=1');

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\VarDumper;

VarDumper::setHandler(function ($var, string $label = null) {
$dumper = new DumpDataCollector();
$cloner = new VarCloner();
$handler = function ($var, string $label = null) use ($dumper, $cloner) {
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
}

$dumper->dump($var);
};
VarDumper::setHandler($handler);
$handler($var, $label);
});

$schemas = new \ArrayObject();
dump($schemas);
$schemas['X'] = new \ArrayObject(['type' => 'object']);

--EXPECTF--
ArrayObject {#%d
-storage: []
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
}
43 changes: 43 additions & 0 deletions Tests/Integration/dump_data_collector2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
Test integration with Symfony's DumpDataCollector
--FILE--
<?php
putenv('NO_COLOR=1');

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\VarDumper;

VarDumper::setHandler(function ($var, string $label = null) {
$dumper = new DumpDataCollector();
$cloner = new VarCloner();
$handler = function ($var, string $label = null) use ($dumper, $cloner) {
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
}

$dumper->dump($var);
};
VarDumper::setHandler($handler);
$handler($var, $label);
});

$schemas = new \ArrayObject();
dump($schemas);
$schemas['X'] = 'A';

--EXPECTF--
ArrayObject {#%d
-storage: []
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
}

0 comments on commit 4e90aa3

Please sign in to comment.