Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Symfony/Component/VarDumper/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
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 src/Symfony/Component/VarDumper/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