File tree 2 files changed +34
-2
lines changed
src/Symfony/Component/VarDumper
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \VarDumper \Dumper ;
13
13
14
14
use Symfony \Component \VarDumper \Cloner \Cursor ;
15
+ use Symfony \Component \VarDumper \Cloner \Stub ;
15
16
16
17
/**
17
18
* CliDumper dumps variables for command line output.
@@ -494,9 +495,10 @@ protected function dumpLine($depth, $endOfValue = false)
494
495
495
496
protected function endValue (Cursor $ cursor )
496
497
{
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 ) {
498
500
$ 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 ) {
500
502
$ this ->line .= ', ' ;
501
503
}
502
504
Original file line number Diff line number Diff line change @@ -130,6 +130,36 @@ public function testDumpWithCommaFlag($expected, $flags)
130
130
$ this ->assertSame ($ expected , $ dump );
131
131
}
132
132
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: "%A/CliDumperTest.php"
148
+ #line: %d
149
+ trace: {
150
+ %A/CliDumperTest.php:%d: {
151
+ :
152
+ : $ex = new \RuntimeException('foo');
153
+ :
154
+ }
155
+ %A
156
+ }
157
+ }
158
+
159
+ EOTXT
160
+ , $ dump );
161
+ }
162
+
133
163
public function provideDumpWithCommaFlagTests ()
134
164
{
135
165
$ expected = <<<'EOTXT'
You can’t perform that action at this time.
0 commit comments