diff --git a/pkg/sqs/SqsProducer.php b/pkg/sqs/SqsProducer.php index 3acdce608..5be9e48d3 100644 --- a/pkg/sqs/SqsProducer.php +++ b/pkg/sqs/SqsProducer.php @@ -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) )); } diff --git a/pkg/sqs/Tests/SqsProducerTest.php b/pkg/sqs/Tests/SqsProducerTest.php index 445b9cef0..2e37c31c6 100644 --- a/pkg/sqs/Tests/SqsProducerTest.php +++ b/pkg/sqs/Tests/SqsProducerTest.php @@ -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()); @@ -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');