File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
src/Symfony/Component/VarDumper Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1212namespace Symfony \Component \VarDumper \Dumper ;
1313
1414use Symfony \Component \VarDumper \Cloner \Cursor ;
15+ use Symfony \Component \VarDumper \Cloner \Stub ;
1516
1617/**
1718 * CliDumper dumps variables for command line output.
@@ -494,9 +495,10 @@ protected function dumpLine($depth, $endOfValue = false)
494495
495496 protected function endValue (Cursor $ cursor )
496497 {
497- if (self ::DUMP_TRAILING_COMMA & $ this ->flags && 0 < $ cursor ->depth ) {
498+ $ isStubArray = (Stub::ARRAY_INDEXED === $ cursor ->hashType || Stub::ARRAY_ASSOC === $ cursor ->hashType );
499+ if (self ::DUMP_TRAILING_COMMA & $ this ->flags && 0 < $ cursor ->depth && $ isStubArray ) {
498500 $ this ->line .= ', ' ;
499- } elseif (self ::DUMP_COMMA_SEPARATOR & $ this ->flags && 1 < $ cursor ->hashLength - $ cursor ->hashIndex ) {
501+ } elseif (self ::DUMP_COMMA_SEPARATOR & $ this ->flags && 1 < $ cursor ->hashLength - $ cursor ->hashIndex && $ isStubArray ) {
500502 $ this ->line .= ', ' ;
501503 }
502504
Original file line number Diff line number Diff line change @@ -130,6 +130,36 @@ public function testDumpWithCommaFlag($expected, $flags)
130130 $ this ->assertSame ($ expected , $ dump );
131131 }
132132
133+ public function testDumpWithCommaFlagsAndExceptionCodeExcerpt ()
134+ {
135+ $ dumper = new CliDumper (null , null , CliDumper::DUMP_TRAILING_COMMA );
136+ $ dumper ->setColors (false );
137+ $ cloner = new VarCloner ();
138+
139+ $ ex = new \RuntimeException ('foo ' );
140+
141+ $ dump = $ dumper ->dump ($ cloner ->cloneVar ($ ex )->withRefHandles (false ), true );
142+
143+ $ this ->assertStringMatchesFormat (<<<'EOTXT'
144+ RuntimeException {
145+ #message: "foo"
146+ #code: 0
147+ #file: "%ACliDumperTest.php"
148+ #line: %d
149+ trace: {
150+ %ACliDumperTest.php:%d: {
151+ :
152+ : $ex = new \RuntimeException('foo');
153+ :
154+ }
155+ %A
156+ }
157+ }
158+
159+ EOTXT
160+ , $ dump );
161+ }
162+
133163 public function provideDumpWithCommaFlagTests ()
134164 {
135165 $ expected = <<<'EOTXT'
You can’t perform that action at this time.
0 commit comments