Skip to content

Explaining the stopFollowingRedirects() restriction for email #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Codeception/Module/Symfony/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ trait MailerAssertionsTrait
{
/**
* Checks that no email was sent.
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first; otherwise this check will *always* pass.
*/
public function dontSeeEmailIsSent(): void
{
$this->assertThat($this->getMessageMailerEvents(), new MailerConstraint\EmailCount(0));
}

/**
* Checks if the desired number of emails was sent.
* Asserts that 1 email was sent by default, specify the `expectedCount` parameter to modify it.
* The email is checked using Symfony message logger, which means:
* * If your app performs a redirect after sending the email, you need to suppress it using [stopFollowingRedirects](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects).
* Checks if the given number of emails was sent (default `$expectedCount`: 1).
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
*
* ```php
* <?php
Expand All @@ -39,6 +40,8 @@ public function seeEmailIsSent(int $expectedCount = 1): void

/**
* Returns the last sent email.
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
*
* ```php
* <?php
Expand All @@ -61,6 +64,8 @@ public function grabLastSentEmail(): ?Email

/**
* Returns an array of all sent emails.
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
* If your app performs a HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
*
* ```php
* <?php
Expand Down Expand Up @@ -90,4 +95,4 @@ protected function getMessageMailerEvents(): MessageEvents

$this->fail("Emails can't be tested without Symfony Mailer service.");
}
}
}