Skip to content

[Messenger] Fix ErrorDetailsStamp denormalization #41378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Messenger/Stamp/ErrorDetailsStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ErrorDetailsStamp implements StampInterface
/** @var string */
private $exceptionClass;

/** @var int|mixed */
/** @var int|string */
private $exceptionCode;

/** @var string */
Expand All @@ -33,7 +33,7 @@ final class ErrorDetailsStamp implements StampInterface
private $flattenException;

/**
* @param int|mixed $exceptionCode
* @param int|string $exceptionCode
*/
public function __construct(string $exceptionClass, $exceptionCode, string $exceptionMessage, FlattenException $flattenException = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Messenger\Stamp\ErrorDetailsStamp;
use Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand Down Expand Up @@ -70,4 +72,26 @@ public function testDeserialization()
$this->assertInstanceOf(ErrorDetailsStamp::class, $deserializedStamp);
$this->assertEquals($stamp, $deserializedStamp);
}

public function testDeserializationWithStringExceptionCode()
{
$exception = new StringErrorCodeException('exception message', 'some code');
$stamp = ErrorDetailsStamp::create($exception);
$extractor = new ConstructorExtractor([
new ReflectionExtractor(),
]);
$serializer = new Serializer(
new SymfonySerializer([
new ArrayDenormalizer(),
new FlattenExceptionNormalizer(),
new ObjectNormalizer(null, null, null, $extractor, null, null, []),
], [new JsonEncoder()])
);

$deserializedEnvelope = $serializer->decode($serializer->encode(new Envelope(new \stdClass(), [$stamp])));

$deserializedStamp = $deserializedEnvelope->last(ErrorDetailsStamp::class);
$this->assertInstanceOf(ErrorDetailsStamp::class, $deserializedStamp);
$this->assertEquals($stamp, $deserializedStamp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\Messenger\Tests\Stamp;

class StringErrorCodeException extends \Exception
{
public function __construct(string $message, string $code)
{
parent::__construct($message);
$this->code = $code;
}
}