8000 [VarDumper] Add a caster for the FlattenException · symfony/symfony@9842dc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9842dc0

Browse files
lyrixxnicolas-grekas
authored andcommitted
[VarDumper] Add a caster for the FlattenException
1 parent f2ff84f commit 9842dc0

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarDumper\Caster;
1313

14+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1415
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
1516
use Symfony\Component\VarDumper\Cloner\Stub;
1617
use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
@@ -288,6 +289,16 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, boo
288289
return $a;
289290
}
290291

292+
public static function castFlattenException(FlattenException $e, array $a, Stub $stub, bool $isNested)
293+
{
294+
if ($isNested) {
295+
$k = sprintf(Caster::PATTERN_PRIVATE, FlattenException::class, 'traceAsString');
296+
$a[$k] = new CutStub($a[$k]);
297+
}
298+
299+
return $a;
300+
}
301+
291302
private static function filterExceptionArray(string $xClass, array $a, string $xPrefix, int $filter): array
292303
{
293304
if (isset($a[$xPrefix.'trace'])) {

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ abstract class AbstractCloner implements ClonerInterface
9595
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
9696
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
9797
'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
98+
'Symfony\Component\ErrorHandler\Exception\FlattenException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFlattenException'],
9899
'Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
99100

100101
'Imagine\Image\ImageInterface' => ['Symfony\Component\VarDumper\Caster\ImagineCaster', 'castImage'],

src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1516
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
1617
use Symfony\Component\VarDumper\Caster\Caster;
1718
use Symfony\Component\VarDumper\Caster\ExceptionCaster;
@@ -354,4 +355,33 @@ public function testAnonymous()
354355

355356
$this->assertDumpMatchesFormat($expectedDump, $e, Caster::EXCLUDE_VERBOSE);
356357
}
358+
359+
/**
360+
* @requires function \Symfony\Component\ErrorHandler\Exception\FlattenException::create
361+
*/
362+
public function testFlattenException()
363+
{
364+
$f = FlattenException::createFromThrowable(new \Exception('Hello'));
365+
366+
$expectedDump = <<<'EODUMP'
367+
array:1 [
368+
0 => Symfony\Component\ErrorHandler\Exception\FlattenException {
369+
-message: "Hello"
370+
-code: 0
371+
-previous: null
372+
-trace: array:13 %a
373+
-traceAsString: ""…%d
374+
-class: "Exception"
375+
-statusCode: 500
376+
-statusText: "Internal Server Error"
377+
-headers: []
378+
-file: "%s/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php"
379+
-line: %d
380+
-asString: null
381+
}
382+
]
383+
EODUMP;
384+
385+
$this->assertDumpMatchesFormat($expectedDump, [$f], Caster::EXCLUDE_VERBOSE);
386+
}
357387
}

0 commit comments

Comments
 (0)
0