Skip to content

[Messenger] SerializerStamp is never used in decode #29970

Closed
@kunicmarko20

Description

@kunicmarko20

Symfony version(s) affected: 4.2

Description
SerializerStamp won't be used in decode.

if (isset($stamps[SerializerStamp::class])) {
$context = end($stamps[SerializerStamp::class])->getContext() + $context;
}

This will never be true because decodeStamps returns:

array(1) {
      │   [0]=>
      │   object(Symfony\Component\Messenger\Stamp\SerializerStamp)#1012 (1) {
      │     ["context":"Symfony\Component\Messenger\Stamp\SerializerStamp":private]=>
      │     array(0) {
      │     }
      │   }
      │ }

And isset($stamps[SerializerStamp::class]) is checking the key which is 0 here.

public function testEncodedWithSymfonySerializerForStamps()
{
$serializer = new Serializer();
$envelope = (new Envelope(new DummyMessage('Hello')))
->with($serializerStamp = new SerializerStamp([ObjectNormalizer::GROUPS => ['foo']]))
->with($validationStamp = new ValidationStamp(['foo', 'bar']))
;
$encoded = $serializer->encode($envelope);
$this->assertArrayHasKey('body', $encoded);
$this->assertArrayHasKey('headers', $encoded);
$this->assertArrayHasKey('type', $encoded['headers']);
$this->assertArrayHasKey('X-Message-Stamp-'.SerializerStamp::class, $encoded['headers']);
$this->assertArrayHasKey('X-Message-Stamp-'.ValidationStamp::class, $encoded['headers']);
$decoded = $serializer->decode($encoded);
$this->assertEquals($serializerStamp, $decoded->last(SerializerStamp::class));
$this->assertEquals($validationStamp, $decoded->last(ValidationStamp::class));
}

This test never checked if the group is actually applied, it just checks if stamp is there and it will always be there, it just won't be used.

How to reproduce
Install messenger with Symfony serializer, add SerializerStamp and see if it is used when you get a response.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions