Replies: 2 comments 7 replies
-
Hmm, I'll investigate this. Can you create a repo? Heya, thanks for reporting. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up. laravel new bug-report --github="--public" Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Ah sorry @ju5t. I just realized this indeed won't work. You can't assert that the MessageSent event was fired because it doesn't get fired with the MailFake class. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
@driesvints sorry for barging into your notifications like this, but because you made the PR for Symfony's mailer, I'm trying my luck here. Sorry for that!
We have an event listener on
Illuminate\Mail\Events\MessageSent
. We have a requirement to store outgoing emails and link them to a related model. TheMessageSent
event only contains a message along with a data array. We enhance the data array withbuildViewDataUsing()
in theMailable
, which gives us the data we need in our listener. All well so far. It works.Testing this beast is different. Our test looks like this:
This does't catch the
MessageSent
event, neither did it when removingMail::fake()
. I did some source surfing, and saw thatMailer
acceptsDispatcher
as an argument when constructing the class. TheMailManager
is doing this, it fetchesevents
from the IoC and passes it on.I get all of this.
But I can't wrap my head around why
Event::fake()
isn't seeing theMessageSent
event. I have guesses:mailer
is initialised before I runEvent::fake()
and as such it can't catch the event? I'm not sure.ArrayTransport
which doesn't send an event? RemovingMAIL_MAILER
from my phpunit.xml has no effect.The Framework tests for
MessageSent
mocks the dispatcher and creates its ownMailer
. I'm afraid that if I do that, I end up mocking too much; and it's not necessarily something I prefer.How can I make my test work?
Beta Was this translation helpful? Give feedback.
All reactions