diff --git a/src/Message/MessageFactory.php b/src/Message/MessageFactory.php index 20505c2..bd499e1 100644 --- a/src/Message/MessageFactory.php +++ b/src/Message/MessageFactory.php @@ -18,7 +18,7 @@ public static function fromMailhogResponse(array $mailhogResponse): Message ContactCollection::fromString($headers['To'][0] ?? ''), ContactCollection::fromString($headers['Cc'][0] ?? ''), ContactCollection::fromString($headers['Bcc'][0] ?? ''), - isset($headers['Subject'][0]) ? $headers['Subject'][0] : '', + $headers['Subject'][0] ?? '', !$mimeParts->isEmpty() ? $mimeParts->getBody() : static::getBodyFrom($mailhogResponse['Content']), diff --git a/tests/integration/MailhogClientTest.php b/tests/integration/MailhogClientTest.php index 0565305..e727ed8 100644 --- a/tests/integration/MailhogClientTest.php +++ b/tests/integration/MailhogClientTest.php @@ -73,6 +73,21 @@ public function it_should_receive_all_message_data() $this->assertEquals('Test body', $message->body); } + /** + * @test + */ + public function it_should_handle_message_without_subject_correctly() + { + $this->sendMessage( + $this->createBasicMessage('me@myself.example', 'myself@myself.example', '', 'Test body') + ); + + /** @var Message $message */ + $message = iterator_to_array($this->client->findAllMessages())[0]; + + $this->assertEquals('', $message->subject); + } + /** * @test */