Skip to content

Commit

Permalink
Merge pull request #478 from elazar/hotfix/sqs-empty-message-body
Browse files Browse the repository at this point in the history
Prevent SqsProducer from sending messages with empty bodies
  • Loading branch information
makasim authored Aug 4, 2018
2 parents 18c7e4a + 0b17385 commit 832e88c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/sqs/SqsProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function send(PsrDestination $destination, PsrMessage $message)
InvalidMessageException::assertMessageInstanceOf($message, SqsMessage::class);

$body = $message->getBody();
if (is_scalar($body) || null === $body) {
if (is_scalar($body) && strlen($body) > 0) {
$body = (string) $body;
} else {
throw new InvalidMessageException(sprintf(
'The message body must be a scalar or null. Got: %s',
'The message body must be a non-empty string. Got: %s',
is_object($body) ? get_class($body) : gettype($body)
));
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sqs/Tests/SqsProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCouldBeConstructedWithRequiredArguments()
public function testShouldThrowIfBodyOfInvalidType()
{
$this->expectException(InvalidMessageException::class);
$this->expectExceptionMessage('The message body must be a scalar or null. Got: stdClass');
$this->expectExceptionMessage('The message body must be a non-empty string. Got: stdClass');

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

Expand Down Expand Up @@ -72,7 +72,7 @@ public function testShouldThrowIfSendMessageFailed()
;

$destination = new SqsDestination('queue-name');
$message = new SqsMessage();
$message = new SqsMessage('foo');

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

0 comments on commit 832e88c

Please sign in to comment.