diff --git a/src/Util/Email.php b/src/Util/Email.php index a9699db..3ba228b 100644 --- a/src/Util/Email.php +++ b/src/Util/Email.php @@ -50,7 +50,7 @@ public function getRecipients(): array public function getSubject(): string { - return $this->subject; + return $this->subject ?? ''; } public function getSource(): string diff --git a/tests/unit/Module/MailCatcherTest.php b/tests/unit/Module/MailCatcherTest.php index f27377c..9a53222 100644 --- a/tests/unit/Module/MailCatcherTest.php +++ b/tests/unit/Module/MailCatcherTest.php @@ -95,6 +95,24 @@ public function testDontSeeInLastEmailSubject() $mailcatcher->dontSeeInLastEmailSubject('Hello world'); } + public function testDontSeeInLastEmailSubjectWithoutSubject() + { + $mailcatcher = new MailCatcherTest_TestClass(); + $mailcatcher->setLastMessage(new Email(1, [], null, '')); + + $mailcatcher->dontSeeInLastEmailSubject('Hello world'); + } + + public function testSeeInLastEmailSubjectWithoutSubjectFails() + { + $mailcatcher = new MailCatcherTest_TestClass(); + $mailcatcher->setLastMessage(new Email(1, [], null, '')); + + $this->expectException(AssertionFailedError::class); + + $mailcatcher->seeInLastEmailSubject('Hello world'); + } + public function testLastMessageToNoMessages() { $handler = new MockHandler([ diff --git a/tests/unit/Util/EmailTest.php b/tests/unit/Util/EmailTest.php index ce3bf75..196d971 100644 --- a/tests/unit/Util/EmailTest.php +++ b/tests/unit/Util/EmailTest.php @@ -14,6 +14,18 @@ public function testGetters() $this->assertEquals('Source body', $email->getSource()); } + public function testMissingSubjectIsEmpty() + { + $email = Email::createFromMailcatcherData([ + 'id' => 1, + 'recipients' => ['some@email.com'], + 'subject' => null, + 'source' => 'Source body' + ]); + + $this->assertSame('', $email->getSubject()); + } + public function testCreateFromMailcatcherData() { $email = Email::createFromMailcatcherData([