From 8a8b0da13b251390e5ac77ac581025fb64dc8e10 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Fri, 8 Oct 2021 08:44:23 -0400 Subject: [PATCH] [feature] add TestEmail::assertSubjectContains() --- README.md | 1 + src/TestEmail.php | 7 +++++++ tests/InteractsWithMailerTest.php | 1 + 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 8605007..59129eb 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ class MyTest extends KernelTestCase // or WebTestCase $this->mailer()->assertEmailSentTo('kevin@example.com', function(TestEmail $email) { $email ->assertSubject('Email Subject') + ->assertSubjectContains('Subject') ->assertFrom('from@example.com') ->assertReplyTo('reply@example.com') ->assertCc('cc1@example.com') diff --git a/src/TestEmail.php b/src/TestEmail.php index def1d28..82b64e9 100644 --- a/src/TestEmail.php +++ b/src/TestEmail.php @@ -122,6 +122,13 @@ final public function assertSubject(string $expected): self return $this; } + final public function assertSubjectContains(string $needle): self + { + Assert::that($this->email->getSubject())->contains($needle); + + return $this; + } + final public function assertFrom(string $expectedEmail, string $expectedName = ''): self { foreach ($this->email->getFrom() as $address) { diff --git a/tests/InteractsWithMailerTest.php b/tests/InteractsWithMailerTest.php index e6fc5e4..9503735 100644 --- a/tests/InteractsWithMailerTest.php +++ b/tests/InteractsWithMailerTest.php @@ -63,6 +63,7 @@ public function can_assert_email_sent(string $environment): void ->assertCc('cc@example.com') ->assertBcc('bcc@example.com') ->assertReplyTo('reply@example.com') + ->assertSubjectContains('sub') ->assertHtmlContains('html body') ->assertTextContains('text body') ->assertContains('body')