-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use already existing assertion for sender email
- Loading branch information
Showing
1 changed file
with
3 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ public function it_sends_email_rendered_with_given_template(): void | |
$this->assertEmailHtmlBodyContains($email, 'Test email body'); | ||
$this->assertEmailHasHeader($email, 'subject', 'Test email subject'); | ||
$this->assertEmailHasSenderName($email, 'Sender'); | ||
$this->assertEmailHasSenderEmail($email, '[email protected]'); | ||
$this->assertEmailAddressContains($email, 'From', '[email protected]'); | ||
} | ||
|
||
/** @test */ | ||
|
@@ -59,7 +59,7 @@ public function it_sends_email_rendered_with_given_template_and_data(): void | |
$this->assertEmailHtmlBodyContains($email, 'Test email body. Data: Test data.'); | ||
$this->assertEmailHasHeader($email, 'subject', 'Test email with data subject'); | ||
$this->assertEmailHasSenderName($email, 'Sender'); | ||
$this->assertEmailHasSenderEmail($email, '[email protected]'); | ||
$this->assertEmailAddressContains($email, 'From', '[email protected]'); | ||
} | ||
|
||
/** @test */ | ||
|
@@ -90,7 +90,7 @@ public function it_sends_conditionally_modified_email(): void | |
$this->assertEmailHtmlBodyContains($email, 'Test email body'); | ||
$this->assertEmailHasHeader($email, 'subject', 'Test email subject'); | ||
$this->assertEmailHasSenderName($email, 'Modified sender name'); | ||
$this->assertEmailHasSenderEmail($email, '[email protected]'); | ||
$this->assertEmailAddressContains($email, 'From', '[email protected]'); | ||
} | ||
|
||
private function assertEmailHasSenderName(?RawMessage $email, string $sender): void | ||
|
@@ -104,16 +104,4 @@ private function assertEmailHasSenderName(?RawMessage $email, string $sender): v | |
|
||
throw new ExpectationFailedException(sprintf('There is no email sent by sender with name "%s"', $sender)); | ||
} | ||
|
||
private function assertEmailHasSenderEmail(?RawMessage $email, string $emailAddress): void | ||
{ | ||
/** @var Address $address */ | ||
foreach ($email->getHeaders()->get('from')->getAddresses() as $address) { | ||
if ($address->getAddress() === $emailAddress) { | ||
return; | ||
} | ||
} | ||
|
||
throw new ExpectationFailedException(sprintf('There is no email sent by sender with email "%s"', $emailAddress)); | ||
} | ||
} |