Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 907ffa0

Browse filesBrowse files
bug #36230 [VarDumper] Fix CliDumper coloration on light arrays (l-vo)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] Fix CliDumper coloration on light arrays | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | When `AbstractDumper::DUMP_LIGHT_ARRAY` is used with the `CliDumper`, the first line (opening bracket) is not colored. When an empty array is dumped (with or without `AbstractDumper::DUMP_LIGHT_ARRAY`) the array is not colored too. This PR aims to fix that. Commits ------- 7af3469 [VarDumper] Fix CliDumper coloration
2 parents c16bb52 + 7af3469 commit 907ffa0
Copy full SHA for 907ffa0

File tree

2 files changed

+54
-1
lines changed
Filter options

2 files changed

+54
-1
lines changed

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
268268
} elseif (Cursor::HASH_RESOURCE === $type) {
269269
$prefix = $this->style('note', $class.' resource').($hasChild ? ' {' : ' ');
270270
} else {
271-
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class).' [' : '[';
271+
$unstyledPrefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? 'array:'.$class : '';
272+
$prefix = $this->style('note', $unstyledPrefix).($unstyledPrefix ? ' [' : '[');
272273
}
273274

274275
if ($cursor->softRefCount || 0 < $cursor->softRefHandle) {

‎src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Cloner\VarCloner;
16+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
1617
use Symfony\Component\VarDumper\Dumper\CliDumper;
1718
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1819
use Twig\Environment;
@@ -572,6 +573,57 @@ public function testIncompleteClass()
572573
);
573574
}
574575

576+
public function provideDumpArrayWithColor()
577+
{
578+
yield [
579+
['foo' => 'bar'],
580+
0,
581+
<<<EOTXT
582+
\e[0;38;5;208m\e[38;5;38marray:1\e[0;38;5;208m [\e[m
583+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
584+
\e[0;38;5;208m]\e[m
585+
586+
EOTXT
587+
];
588+
589+
yield [[], AbstractDumper::DUMP_LIGHT_ARRAY, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
590+
591+
yield [
592+
['foo' => 'bar'],
593+
AbstractDumper::DUMP_LIGHT_ARRAY,
594+
<<<EOTXT
595+
\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[\e[m
596+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
597+
\e[0;38;5;208m]\e[m
598+
599+
EOTXT
600+
];
601+
602+
yield [[], 0, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
603+
}
604+
605+
/**
606+
* @dataProvider provideDumpArrayWithColor
607+
*/
608+
public function testDumpArrayWithColor($value, $flags, $expectedOut)
609+
{
610+
if ('\\' === \DIRECTORY_SEPARATOR) {
611+
$this->markTestSkipped('Windows console does not support coloration');
612+
}
613+
614+
$out = '';
615+
$dumper = new CliDumper(function ($line, $depth) use (&$out) {
616+
if ($depth >= 0) {
617+
$out .= str_repeat(' ', $depth).$line."\n";
618+
}
619+
}, null, $flags);
620+
$dumper->setColors(true);
621+
$cloner = new VarCloner();
622+
$dumper->dump($cloner->cloneVar($value));
623+
624+
$this->assertSame($expectedOut, $out);
625+
}
626+
575627
private function getSpecialVars()
576628
{
577629
foreach (array_keys($GLOBALS) as $var) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.