-
Notifications
You must be signed in to change notification settings - Fork 25
Update MailerAssertionsTrait.php: Adding Mailpit #204
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ public function assertQueuedEmailCount(int $count, ?string $transport = null, st | |
/** | ||
* Checks that no email was sent. | ||
* The check is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means: | ||
* If your app performs an HTTP redirect, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first; otherwise this check will *always* pass. | ||
* If your app performs an HTTP redirect, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first; otherwise this check will *always* pass. | ||
*/ | ||
public function dontSeeEmailIsSent(): void | ||
{ | ||
|
@@ -60,7 +60,7 @@ public function dontSeeEmailIsSent(): void | |
/** | ||
* Returns the last sent email. | ||
* The function is based on `\Symfony\Component\Mailer\EventListener\MessageLoggerListener`, which means: | ||
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first. | ||
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
* See also: [grabSentEmails()](https://codeception.com/docs/modules/Symfony#grabSentEmails) | ||
* | ||
* ```php | ||
|
@@ -82,7 +82,7 @@ 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 an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first. | ||
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
* See also: [grabLastSentEmail()](https://codeception.com/docs/modules/Symfony#grabLastSentEmail) | ||
* | ||
* ```php | ||
|
@@ -100,7 +100,12 @@ public function grabSentEmails(): array | |
/** | ||
* 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 an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first. | ||
* If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
* | ||
* Limitation: | ||
* If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), | ||
* Codeception will not notice it. | ||
* As a more professional alternative, we recommend Mailpit, wchich also lets you test the content of the mail. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is not clear why it is more 'professional'. Please explain what Mailpit is and how it works as an alternative to what within Codeception exactly, in what specific scenario you are going to recommend its use and how to integrate it into the functional testing workflow with this module. by the way, there is a tiny typo in 'wchich'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please merge Codeception/codeception.github.com#880 first, so I can add a link to it here. I don't think adding all features of Mailpit here is a good idea, cause nobody will ever update that :-) |
||
* | ||
* ```php | ||
* <?php | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please clarify if this problem is also present in runSymfonyConsoleCommand, because when reading it seems to be exclusive of runShellCommand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I tried. But the mail assertions are working by looking at the web debug toolbar, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't try
runSymfonyConsoleCommand()
. Is there a way to pipe input to the command?Right now, I'm doing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThomasLandauer yes, you can use the third parameter
$consoleInputs
for that. So the equivalent to the above would beThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, then the test executions hangs at this line - looks like the console is waiting for something. I didn't look into it further - are you sure that this works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThomasLandauer I tested it before writing that comment just to be sure, so yes, it does work in general. Maybe we're talking about different things, so I created Codeception/symfony-module-tests#28 to demonstrate what I'm talking about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is a cool idea!
My command doesn't ask questions (i.e. doesn't wait for input), it reads input from STDIN:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThomasLandauer oh, I see. I didn't have such a use case yet, so I don't know, but the console input parameter might indeed not work with STDIN then.