Skip to content

Commit

Permalink
[VarDumper] Fix managing collapse state in CliDumper
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 24, 2023
1 parent e706c99 commit 684b36f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function setDisplayOptions(array $displayOptions)
public function dumpScalar(Cursor $cursor, string $type, $value)
{
$this->dumpKey($cursor);
$this->collapseNextHash = $this->expandNextHash = false;

$style = 'const';
$attr = $cursor->attr;
Expand Down Expand Up @@ -191,6 +192,7 @@ public function dumpScalar(Cursor $cursor, string $type, $value)
public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
{
$this->dumpKey($cursor);
$this->collapseNextHash = $this->expandNextHash = false;
$attr = $cursor->attr;

if ($bin) {
Expand Down Expand Up @@ -286,6 +288,7 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild)
}

$this->dumpKey($cursor);
$this->expandNextHash = false;
$attr = $cursor->attr;

if ($this->collapseNextHash) {
Expand Down
1 change: 0 additions & 1 deletion Tests/Caster/MysqliCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function testNotConnected()

$xCast = <<<EODUMP
mysqli_driver {%A
+reconnect: false
+report_mode: 3
}
EODUMP;
Expand Down
40 changes: 40 additions & 0 deletions Tests/Dumper/CliDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Caster\CutStub;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
use Symfony\Component\VarDumper\Dumper\CliDumper;
Expand Down Expand Up @@ -549,6 +551,44 @@ public function testDumpArrayWithColor($value, $flags, $expectedOut)
$this->assertSame($expectedOut, $out);
}

public function testCollapse()
{
$stub = new Stub();
$stub->type = Stub::TYPE_OBJECT;
$stub->class = 'stdClass';
$stub->position = 1;

$data = new Data([
[
$stub,
],
[
"\0~collapse=1\0foo" => 123,
"\0+\0bar" => [1 => 2],
],
[
'bar' => 123,
]
]);

$dumper = new CliDumper();
$dump = $dumper->dump($data, true);

$this->assertSame(
<<<'EOTXT'
{
foo: 123
+"bar": array:1 [
"bar" => 123
]
}

EOTXT
,
$dump
);
}

private function getSpecialVars()
{
foreach (array_keys($GLOBALS) as $var) {
Expand Down

0 comments on commit 684b36f

Please sign in to comment.