SerializerStamp example

$decodedEnvelope = $serializer->decode($serializer->encode(new Envelope(new DummyMessage('Hello'))));

        $this->assertEquals(new DummyMessage('Hello')$decodedEnvelope->getMessage());
        $this->assertEquals(new SerializedMessageStamp('{"message":"Hello"}')$decodedEnvelope->last(SerializedMessageStamp::class));
    }

    public function testEncodedWithStampsIsDecodable()
    {
        $serializer = new Serializer();

        $envelope = (new Envelope(new DummyMessage('Hello')))
            ->with(new SerializerStamp([ObjectNormalizer::GROUPS => ['foo']]))
            ->with(new ValidationStamp(['foo', 'bar']))
            ->with(new SerializedMessageStamp('{"message":"Hello"}'))
        ;

        $this->assertEquals($envelope$serializer->decode($serializer->encode($envelope)));
    }

    public function testSerializedMessageStampIsUsedForEncoding()
    {
        $serializer = new Serializer();

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Stamp\SerializerStamp;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

/** * @author Maxime Steinhausser <maxime.steinhausser@gmail.com> */
class SerializerStampTest extends TestCase
{
    public function testSerializable()
    {
        $stamp = new SerializerStamp([ObjectNormalizer::GROUPS => ['Default', 'Extra']]);

        $this->assertEquals($stampunserialize(serialize($stamp)));
    }
}
Home | Imprint | This part of the site doesn't use cookies.