-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Incomplete Mail testing section in 5.3, no "how to" on email testing #15922
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
Comments
assertEmailCount works for me, here's a simple project where the test passes: https://github.com/isarastov/symfony-test-send-mail |
It's still missing in the documentation page I linked. |
Did you try https://github.com/zenstruck/mailer-test cc @kbond |
@OskarStark I did not, was hoping that what symfony provides would be enough. |
The native Symfony email assertions don't use the profiler (but maybe I'm wrong about that)?
|
@kbond the email assertions are done in a method called after the test is run, it's not on another test (I assume that would be where the kernel is rebooted? ) |
I meant if you make multiple requests within the same test the kernel will be rebooted. $client = static::createClient();
$client->request('GET', '/sends-email');
$client->request('GET', '/something-else');
self::assertEmailCount(1); // fails because the kernel was rebooted and the sent messages lost |
Another possibility: does your request redirect after sending the email? I think this reboots the kernel so you'd lose the sent emails. |
It's a post request sent to and endpoint generated by API Platform, with a custom DataPersister, so I'm not 100% sure but I think there are no redirects. |
This package works well with me (I had two test cases where the first succeeded finding one sent email, while the one right after would fail detecting a second mail sent). Thank you |
Closing, as this was fixed by #16195 |
Hello,
I googled for email testing in symfony and got this page: https://symfony.com/doc/4.1/email/testing.html
This is for 4.1 but I am using symfony 5.3 so I clicked the link (which is on the page)
the updated version of this page
I was taken to this page: https://symfony.com/doc/current/mailer.html
This page is a "How to" page and it's missing a
testing
section. The reader is left to guess how to test emails in symfony 5.3.I have asked this in the symfony slack #support channel and got a bit of help but nothing conclusive.
I did a bit more googling and found: symfony/symfony#39511
Where is seems the user that posted the issue has a similar issue and when @xabbuh suggested enabling the
profiler
all the issues went away.So I've done:
I've also done:
But when I do this:
I still get an error saying I have sent zero emails.
When I run code locally I can see an email in
mailhog
. So I know an email is being sent.I think email testing is crucial in any application. I would do PR on how to test emails, if I actually new all the steps to test email, but I don't :(
Can someone please update the docs regarding this issue?
The text was updated successfully, but these errors were encountered: