Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44848ff

Browse files
committed
[VarDumper] Support ThrownExceptionInformation
1 parent 2454cdf commit 44848ff

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

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

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

1414
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
15+
use Symfony\Component\Messenger\Exception\ThrownExceptionDetails;
1516
use Symfony\Component\VarDumper\Cloner\Stub;
1617
use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
1718

@@ -83,6 +84,15 @@ public static function castThrowingCasterException(ThrowingCasterException $e, a
8384
return $a;
8485
}
8586

87+
public static function castThrownExceptionDetails(ThrownExceptionDetails $exceptionDetails, array $a, Stub $stub, bool $isNested, int $filter = 0)
88+
{
89+
$xPrefix = "\0".ThrownExceptionDetails::class."\0";
90+
$stub->class = $exceptionDetails->getClass();
91+
unset($a[$xPrefix.'class']);
92+
93+
return self::filterExceptionArray($exceptionDetails->getClass(), $a, $xPrefix, $filter);
94+
}
95+
8696
public static function castSilencedErrorContext(SilencedErrorContext $e, array $a, Stub $stub, bool $isNested)
8797
{
8898
$sPrefix = "\0".SilencedErrorContext::class."\0";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ abstract class AbstractCloner implements ClonerInterface
9191
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
9292
'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
9393
'Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
94+
'Symfony\Component\Messenger\Exception\ThrownExceptionDetails' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrownExceptionDetails'],
9495

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

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,29 @@ public function testAnonymous()
244244

245245
$this->assertDumpMatchesFormat($expectedDump, $e, Caster::EXCLUDE_VERBOSE);
246246
}
247+
248+
public function testThrownExceptionDetails()
249+
{
250+
$e = \Symfony\Component\ErrorHandler\Exception\FlattenException::createFromThrowable($this->getTestException('foo'));
251+
$exceptionDetails = \Symfony\Component\Messenger\Exception\ThrownExceptionDetails::createFromFlattenException($e);
252+
253+
$expectedDump = <<<'EODUMP'
254+
Exception {
255+
-message: "foo"
256+
-code: 0
257+
-file: "%sExceptionCasterTest.php"
258+
-line: 28
259+
trace: {
260+
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
261+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
262+
› {
263+
› return new \Exception(''.$msg);
264+
› }
265+
}
266+
%s%eTests%eCaster%eExceptionCasterTest.php:250 { …}
267+
%A
268+
EODUMP;
269+
270+
$this->assertDumpMatchesFormat($expectedDump, $exceptionDetails);
271+
}
247272
}

src/Symfony/Component/VarDumper/composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require-dev": {
2424
"ext-iconv": "*",
2525
"symfony/console": "^4.4|^5.0",
26+
"symfony/error-handliner": "^4.4|^5.0",
2627
"symfony/process": "^4.4|^5.0",
2728
"twig/twig": "^2.4|^3.0"
2829
},
@@ -45,5 +46,10 @@
4546
"bin": [
4647
"Resources/bin/var-dump-server"
4748
],
48-
"minimum-stability": "dev"
49+
"minimum-stability": "dev",
50+
"extra": {
51+
"branch-alias": {
52+
"dev-main": "5.3-dev"
53+
}
54+
}
4955
}

0 commit comments

Comments
 (0)