Skip to content

Commit

Permalink
[feature] add TestEmail::assertSubjectContains()
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Oct 8, 2021
1 parent 20d2635 commit 8a8b0da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions src/TestEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/InteractsWithMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 8a8b0da

Please sign in to comment.