SymfonySerializer example

$this->assertSame(\Exception::class$stamp->getExceptionClass());
        $this->assertSame('I am inside', $stamp->getExceptionMessage());
        $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);
    }
$this->context = $context + [self::MESSENGER_SERIALIZATION_CONTEXT => true];
    }

    public static function create(): self
    {
        if (!class_exists(SymfonySerializer::class)) {
            throw new LogicException(sprintf('The "%s" class requires Symfony\'s Serializer component. Try running "composer require symfony/serializer" or use "%s" instead.', __CLASS__, PhpSerializer::class));
        }

        $encoders = [new XmlEncoder()new JsonEncoder()];
        $normalizers = [new DateTimeNormalizer()new ArrayDenormalizer()new ObjectNormalizer()];
        $serializer = new SymfonySerializer($normalizers$encoders);

        return new self($serializer);
    }

    public function decode(array $encodedEnvelope): Envelope
    {
        if (empty($encodedEnvelope['body']) || empty($encodedEnvelope['headers'])) {
            throw new MessageDecodingFailedException('Encoded envelope should have at least a "body" and some "headers", or maybe you should implement your own serializer.');
        }

        if (empty($encodedEnvelope['headers']['type'])) {
            
$this->assertEquals(\count($configuredSenders), \count($stampSenders));

        foreach ($configuredSenders as $key => $sender) {
            $this->assertSame($sender$stampSenders[$key]);
        }
    }

    public function testDeserialization()
    {
        $stamp = new TransportNamesStamp(['foo']);
        $serializer = new Serializer(
            new SymfonySerializer([
                new ArrayDenormalizer(),
                new ObjectNormalizer(),
            ][new JsonEncoder()])
        );

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

        $deserializedStamp = $deserializedEnvelope->last(TransportNamesStamp::class);
        $this->assertInstanceOf(TransportNamesStamp::class$deserializedStamp);
        $this->assertEquals($stamp$deserializedStamp);
    }

    
Home | Imprint | This part of the site doesn't use cookies.