|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\VarDumper\Cloner\VarCloner;
|
| 16 | +use Symfony\Component\VarDumper\Dumper\AbstractDumper; |
16 | 17 | use Symfony\Component\VarDumper\Dumper\CliDumper;
|
17 | 18 | use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
18 | 19 | use Twig\Environment;
|
@@ -572,6 +573,57 @@ public function testIncompleteClass()
|
572 | 573 | );
|
573 | 574 | }
|
574 | 575 |
|
| 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 | + |
575 | 627 | private function getSpecialVars()
|
576 | 628 | {
|
577 | 629 | foreach (array_keys($GLOBALS) as $var) {
|
|
0 commit comments