FlattenExceptionNormalizer example

use Symfony\Component\Messenger\Transport\Serialization\Serializer;

/** * @author Pascal Luna <skalpa@zetareticuli.org> */
class FlattenExceptionNormalizerTest extends TestCase
{
    private FlattenExceptionNormalizer $normalizer;

    protected function setUp(): void
    {
        $this->normalizer = new FlattenExceptionNormalizer();
    }

    public function testSupportsNormalization()
    {
        $this->assertTrue($this->normalizer->supportsNormalization(new FlattenException(), null, $this->getMessengerContext()));
        $this->assertFalse($this->normalizer->supportsNormalization(new FlattenException()));
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
    }

    /** * @dataProvider provideFlattenException */
$this->assertSame(123, $stamp->getExceptionCode());
        $this->assertEquals($flattenException$stamp->getFlattenException());
    }

    public function testDeserialization()
    {
        $exception = new \Exception('exception message');
        $stamp = ErrorDetailsStamp::create($exception);
        $serializer = new Serializer(
            new SymfonySerializer([
                new ArrayDenormalizer(),
                new FlattenExceptionNormalizer(),
                new ObjectNormalizer(),
            ][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);
    }
}
Home | Imprint | This part of the site doesn't use cookies.