8000 [Messenger] Fix `ErrorDetailsStamp` denormalization · symfony/symfony@09eec5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 09eec5e

Browse files
wucdbmfabpot
authored andcommitted
[Messenger] Fix ErrorDetailsStamp denormalization
1 parent 67d8a59 commit 09eec5e

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/Symfony/Component/Messenger/Stamp/ErrorDetailsStamp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ErrorDetailsStamp implements StampInterface
2323
/** @var string */
2424
private $exceptionClass;
2525

26-
/** @var int|mixed */
26+
/** @var int|string */
2727
private $exceptionCode;
2828

2929
/** @var string */
@@ -33,7 +33,7 @@ final class ErrorDetailsStamp implements StampInterface
3333
private $flattenException;
3434

3535
/**
36-
* @param int|mixed $exceptionCode
36+
* @param int|string $exceptionCode
3737
*/
3838
public function __construct(string $exceptionClass, $exceptionCode, string $exceptionMessage, FlattenException $flattenException = null)
3939
{

src/Symfony/Component/Messenger/Tests/Stamp/ErrorDetailsStampTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\Messenger\Stamp\ErrorDetailsStamp;
1919
use Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer;
2020
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
21+
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
22+
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
2123
use Symfony\Component\Serializer\Encoder\JsonEncoder;
2224
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
2325
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@@ -70,4 +72,26 @@ public function testDeserialization()
7072
$this->assertInstanceOf(ErrorDetailsStamp::class, $deserializedStamp);
7173
$this->assertEquals($stamp, $deserializedStamp);
7274
}
75+
76+
public function testDeserializationWithStringExceptionCode()
77+
{
78+
$exception = new StringErrorCodeException('exception message', 'some code');
79+
$stamp = ErrorDetailsStamp::create($exception);
80+
$extractor = new ConstructorExtractor([
81+
new ReflectionExtractor(),
82+
]);
83+
$serializer = new Serializer(
84+
new SymfonySerializer([
85+
new ArrayDenormalizer(),
86+
new FlattenExceptionNormalizer(),
87+
new ObjectNormalizer(null, null, null, $extractor, null, null, []),
88+
], [new JsonEncoder()])
89+
);
90+
91+
$deserializedEnvelope = $serializer->decode($serializer->encode(new Envelope(new \stdClass(), [$stamp])));
92+
93+
$deserializedStamp = $deserializedEnvelope->last(ErrorDetailsStamp::class);
94+
$this->assertInstanceOf(ErrorDetailsStamp::class, $deserializedStamp);
95+
$this->assertEquals($stamp, $deserializedStamp);
96+
}
7397
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Messenger\Tests\Stamp;
4+
5+
class StringErrorCodeException extends \Exception
6+
{
7+
public function __construct(string $message, string $code)
8+
{
9+
parent::__construct($message);
10+
$this->code = $code;
11+
}
12+
}

0 commit comments

Comments
 (0)
0