diff --git a/Dumper/CliDumper.php b/Dumper/CliDumper.php index c155d4c..b3358f5 100644 --- a/Dumper/CliDumper.php +++ b/Dumper/CliDumper.php @@ -134,6 +134,7 @@ public function setDisplayOptions(array $displayOptions) public function dumpScalar(Cursor $cursor, string $type, string|int|float|bool|null $value) { $this->dumpKey($cursor); + $this->collapseNextHash = $this->expandNextHash = false; $style = 'const'; $attr = $cursor->attr; @@ -197,6 +198,7 @@ public function dumpScalar(Cursor $cursor, string $type, string|int|float|bool|n public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut) { $this->dumpKey($cursor); + $this->collapseNextHash = $this->expandNextHash = false; $attr = $cursor->attr; if ($bin) { @@ -290,6 +292,7 @@ public function enterHash(Cursor $cursor, int $type, string|int|null $class, boo $this->colors ??= $this->supportsColors(); $this->dumpKey($cursor); + $this->expandNextHash = false; $attr = $cursor->attr; if ($this->collapseNextHash) { diff --git a/Tests/Caster/MysqliCasterTest.php b/Tests/Caster/MysqliCasterTest.php index 983f541..4eba406 100644 --- a/Tests/Caster/MysqliCasterTest.php +++ b/Tests/Caster/MysqliCasterTest.php @@ -30,7 +30,6 @@ public function testNotConnected() $xCast = <<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 + ); + } }