Skip to content

Commit

Permalink
Use already existing assertion for sender email
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Jan 9, 2023
1 parent 1574bc7 commit 9f40a59
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Bundle/tests/Functional/SymfonyMailerSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}

0 comments on commit 9f40a59

Please sign in to comment.