Skip to content

Commit 684b36f

Browse files
[VarDumper] Fix managing collapse state in CliDumper
1 parent e706c99 commit 684b36f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: Dumper/CliDumper.php

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function setDisplayOptions(array $displayOptions)
128128
public function dumpScalar(Cursor $cursor, string $type, $value)
129129
{
130130
$this->dumpKey($cursor);
131+
$this->collapseNextHash = $this->expandNextHash = false;
131132

132133
$style = 'const';
133134
$attr = $cursor->attr;
@@ -191,6 +192,7 @@ public function dumpScalar(Cursor $cursor, string $type, $value)
191192
public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
192193
{
193194
$this->dumpKey($cursor);
195+
$this->collapseNextHash = $this->expandNextHash = false;
194196
$attr = $cursor->attr;
195197

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

288290
$this->dumpKey($cursor);
291+
$this->expandNextHash = false;
289292
$attr = $cursor->attr;
290293

291294
if ($this->collapseNextHash) {

Diff for: Tests/Caster/MysqliCasterTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function testNotConnected()
3030

3131
$xCast = <<<EODUMP
3232
mysqli_driver {%A
33-
+reconnect: false
3433
+report_mode: 3
3534
}
3635
EODUMP;

Diff for: Tests/Dumper/CliDumperTest.php

+40
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Caster\CutStub;
16+
use Symfony\Component\VarDumper\Cloner\Data;
17+
use Symfony\Component\VarDumper\Cloner\Stub;
1618
use Symfony\Component\VarDumper\Cloner\VarCloner;
1719
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
1820
use Symfony\Component\VarDumper\Dumper\CliDumper;
@@ -549,6 +551,44 @@ public function testDumpArrayWithColor($value, $flags, $expectedOut)
549551
$this->assertSame($expectedOut, $out);
550552
}
551553

554+
public function testCollapse()
555+
{
556+
$stub = new Stub();
557+
$stub->type = Stub::TYPE_OBJECT;
558+
$stub->class = 'stdClass';
559+
$stub->position = 1;
560+
561+
$data = new Data([
562+
[
563+
$stub,
564+
],
565+
[
566+
"\0~collapse=1\0foo" => 123,
567+
"\0+\0bar" => [1 => 2],
568+
],
569+
[
570+
'bar' => 123,
571+
]
572+
]);
573+
574+
$dumper = new CliDumper();
575+
$dump = $dumper->dump($data, true);
576+
577+
$this->assertSame(
578+
<<<'EOTXT'
579+
{
580+
foo: 123
581+
+"bar": array:1 [
582+
"bar" => 123
583+
]
584+
}
585+
586+
EOTXT
587+
,
588+
$dump
589+
);
590+
}
591+
552592
private function getSpecialVars()
553593
{
554594
foreach (array_keys($GLOBALS) as $var) {

0 commit comments

Comments
 (0)