Skip to content

Commit dd66eef

Browse files
Explaining the stopFollowingRedirects() restriction for email (#118)
1 parent 42dda3c commit dd66eef

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Codeception/Module/Symfony/MailerAssertionsTrait.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ trait MailerAssertionsTrait
1313
{
1414
/**
1515
* Checks that no email was sent.
16+
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
17+
* 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.
1618
*/
1719
public function dontSeeEmailIsSent(): void
1820
{
1921
$this->assertThat($this->getMessageMailerEvents(), new MailerConstraint\EmailCount(0));
2022
}
2123

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

4041
/**
4142
* Returns the last sent email.
43+
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
44+
* 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.
4245
*
4346
* ```php
4447
* <?php
@@ -61,6 +64,8 @@ public function grabLastSentEmail(): ?Email
6164

6265
/**
6366
* Returns an array of all sent emails.
67+
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means:
68+
* 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.
6469
*
6570
* ```php
6671
* <?php
@@ -90,4 +95,4 @@ protected function getMessageMailerEvents(): MessageEvents
9095

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

0 commit comments

Comments
 (0)