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

seeEmailIsSent() not working when email is sent by a Symfony/Doctrine entity listener #90

Open
ThomasLandauer opened this issue Jan 5, 2021 · 6 comments

Comments

@ThomasLandauer
Copy link
Member

When using an Entity Listener to send an email, seeEmailIsSent() doesn't notice it. When I do the same email command in the controller, it works.

The actual email delivery works in both cases (as shown by mailcatcher).

Details

  • Codeception version: 2.5.1
  • PHP Version: 7.2
@TavoNiievez TavoNiievez added this to the 2.0.0 milestone Jan 8, 2021
@TavoNiievez TavoNiievez removed this from the 2.0.0 milestone Jan 15, 2021
@TavoNiievez
Copy link
Member

TavoNiievez commented Jan 15, 2021

It seems like something went wrong when GitHub tried to transfer this issue. I am attaching an image of Google's cached version of the most relevant comment.
imagen

@TavoNiievez
Copy link
Member

The Mail Logger for Symfony Mailer also has this problem.

I tried to permanently persist the services as @picoss suggested for Swift Mailer, however it didn't work. So unfortunately this issue will have to be open a little longer.

@bedrich-schindler
Copy link

I have the same issue when sending e-mail this way using Swiftmailer. What more, after update from Symfony 4.4 and older Codeception to Symfony 5.2 and latest Codeception, I get Emails can't be tested without Symfony Mailer service.. If I install symfony/mailer, error disappears but it says that 0 emails were sent.

@Legion112
Copy link

You should not be sending emails in the entity listeners. Nor in doctrine lifecycle.
Why? Her is why https://youtu.be/WW2qPKukoZY?t=1290

@TavoNiievez
Copy link
Member

@Legion112 Thank you very much for the video.
If this is 'the way it is', what would really close this issue would be a link to the official documentation where the same thing that is mentioned in the video is mentioned or where alternatives that someone could use instead of Doctrine Entity Listeners are mentioned.

do you think it's ok @ThomasLandauer ?

@ThomasLandauer
Copy link
Member Author

In short: I don't agree ;-)

In long: Codeception is a testing framework, not a best-practice guide. So besides the fact that for any best-practice there will always be some (strange) situations where breaking them is a good idea. My main argument is: It's not upon us to judge! If somebody does want to send an email from a listener - well, why not - it's their app, not ours ;-)

And besides not agreeing in general, I don't even agree with the video sequence itself: What's wrong with sending out an email on the "persist" event (i.e. when the record is created)? So the essence of the serialize/unserialize example is for me:

Watch out, cause if you don't do it right, you can really mess it up!

Which is a warning you can apply to anything in programming... ;-)

Finally: Following this same argument, we'd also have to remove typeInPopup, cause using window.prompt is certainly an anti-pattern too...

This issue is being transferred. Timeline may not be complete until it finishes.
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

No branches or pull requests

4 participants