Skip to content

Commit 0b17385

Browse files
committed
Prevent SqsProducer from sending messages with empty bodies
Fixes #435
1 parent 22e5315 commit 0b17385

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/sqs/SqsProducer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function send(PsrDestination $destination, PsrMessage $message)
4242
InvalidMessageException::assertMessageInstanceOf($message, SqsMessage::class);
4343

4444
$body = $message->getBody();
45-
if (is_scalar($body) || null === $body) {
45+
if (is_scalar($body) && strlen($body) > 0) {
4646
$body = (string) $body;
4747
} else {
4848
throw new InvalidMessageException(sprintf(
49-
'The message body must be a scalar or null. Got: %s',
49+
'The message body must be a non-empty string. Got: %s',
5050
is_object($body) ? get_class($body) : gettype($body)
5151
));
5252
}

pkg/sqs/Tests/SqsProducerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCouldBeConstructedWithRequiredArguments()
3131
public function testShouldThrowIfBodyOfInvalidType()
3232
{
3333
$this->expectException(InvalidMessageException::class);
34-
$this->expectExceptionMessage('The message body must be a scalar or null. Got: stdClass');
34+
$this->expectExceptionMessage('The message body must be a non-empty string. Got: stdClass');
3535

3636
$producer = new SqsProducer($this->createSqsContextMock());
3737

@@ -72,7 +72,7 @@ public function testShouldThrowIfSendMessageFailed()
7272
;
7373

7474
$destination = new SqsDestination('queue-name');
75-
$message = new SqsMessage();
75+
$message = new SqsMessage('foo');
7676

7777
$this->expectException(\RuntimeException::class);
7878
$this->expectExceptionMessage('Message was not sent');

0 commit comments

Comments
 (0)