Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c60490

Browse files
committed
bug #30466 [Messenger] Make 'headers' key optional for encoded messages (yceruto)
This PR was merged into the 4.2 branch. Discussion ---------- [Messenger] Make 'headers' key optional for encoded messages | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30455 | License | MIT Commits ------- bb881c9 Make 'headers' key optional for encoded messages
2 parents bfcc607 + bb881c9 commit 9c60490

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/AmqpSenderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,19 @@ public function testItSendsTheEncodedMessage()
3737
$sender = new AmqpSender($connection, $serializer);
3838
$sender->send($envelope);
3939
}
40+
41+
public function testItSendsTheEncodedMessageWithoutHeaders()
42+
{
43+
$envelope = new Envelope(new DummyMessage('Oy'));
44+
$encoded = ['body' => '...'];
45+
46+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
47+
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
48+
49+
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
50+
$connection->expects($this->once())->method('publish')->with($encoded['body'], []);
51+
52+
$sender = new AmqpSender($connection, $serializer);
53+
$sender->send($envelope);
54+
}
4055
}

src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpSender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function send(Envelope $envelope): Envelope
4141
{
4242
$encodedMessage = $this->serializer->encode($envelope);
4343

44-
$this->connection->publish($encodedMessage['body'], $encodedMessage['headers']);
44+
$this->connection->publish($encodedMessage['body'], $encodedMessage['headers'] ?? []);
4545

4646
return $envelope;
4747
}

0 commit comments

Comments
 (0)