Skip to content
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

Update MailerAssertionsTrait.php: Adding Mailpit #204

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ThomasLandauer
Copy link
Member

I will add a link to Mailpit, as soon as Codeception/codeception.github.com#880 is merged.

* 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),
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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:

$I->runShellCommand('printf "foobar" | php bin/console app:my_command --env=test');

Copy link
Contributor

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 be

$I->runSymfonyConsoleCommand('app:my_command', ['--env' => 'test'], ['foobar']);

* 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.
Copy link
Member

Choose a reason for hiding this comment

The 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'.

Copy link
Member Author

@ThomasLandauer ThomasLandauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to get rid of the "Pending" badge at some of my comments...

EDIT: Looks like they (see below) weren't actually published till right now...

* 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),
Copy link
Member Author

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?

* 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.
Copy link
Member Author

Choose a reason for hiding this comment

The 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 :-)
IMO the main advantage is that you can assert the mail's content. And sooner or later most people probably want a mailcatching solution anyway (not just for testing, but also for development), so I'm figuring it's a good idea to tell them early...

* 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),
Copy link
Member Author

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:

$I->runShellCommand('printf "foobar" | php bin/console app:my_command --env=test');

@ThomasLandauer
Copy link
Member Author

Looks like I cannot link to Mailpit's entry at https://codeception.com/addons directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants