Make 'headers' key optional for encoded messages

This commit is contained in:
Yonel Ceruto 2019-03-06 15:21:57 -05:00
parent 675c45850c
commit bb881c9cd0
2 changed files with 16 additions and 1 deletions

View File

@ -37,4 +37,19 @@ class AmqpSenderTest extends TestCase
$sender = new AmqpSender($connection, $serializer);
$sender->send($envelope);
}
public function testItSendsTheEncodedMessageWithoutHeaders()
{
$envelope = new Envelope(new DummyMessage('Oy'));
$encoded = ['body' => '...'];
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection->expects($this->once())->method('publish')->with($encoded['body'], []);
$sender = new AmqpSender($connection, $serializer);
$sender->send($envelope);
}
}

View File

@ -41,7 +41,7 @@ class AmqpSender implements SenderInterface
{
$encodedMessage = $this->serializer->encode($envelope);
$this->connection->publish($encodedMessage['body'], $encodedMessage['headers']);
$this->connection->publish($encodedMessage['body'], $encodedMessage['headers'] ?? []);
return $envelope;
}