Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [VarDumper] Fix managing collapse state in CliDumper
  • Loading branch information
fabpot committed Aug 24, 2023
2 parents 77fb4f2 + 684b36f commit 2027be1
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 @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
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 @@ -455,4 +457,42 @@ 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
);
}
}

0 comments on commit 2027be1

Please sign in to comment.