H
H
Holmess882021-01-21 10:43:38
Laravel
Holmess88, 2021-01-21 10:43:38

Why don't expectsNotification or similar tools catch notifications in tests?

Hello! A question.
For example.

I have a notification in code that queues a password reset email to be sent to the user. I can silence it. But! Laravel testing tools give me the opportunity to catch them, i.e. not just to score on them, but to make sure that they were actually processed. But, for some reason, neither expectsNotification nor Notification::assertSentTo() do what I expect from them. The following error occurs in the test: The following expected notification were not dispatched. In the code, the notification is sent as Notifications::send(destination)

I additionally wrote artisan commands to start processing the queue, but this also did not help to pass the assertion that the notification was processed.

Maybe someone has come across such a question and knows the answer what is wrong and why the statement does not pass?

Laravel 5.8

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Holmess88, 2021-01-21
@Holmess88

I looked at the logs, maybe the problem is that my notification actually goes into the failed status?
That is, since I don't have smtp configured locally, I don't have anyone to send messages to.
The log is something like this: Processing x3 -> Failed. The queue tries to process three times, then removes from processing.
Process could not be started /usr/sbin/sendmail
Which is not entirely logical, because the notification was faked. And then I don’t understand the meaning of fake, if it doesn’t matter to me that the message was sent, it matters to me that it intended to be sent.
I rewrote under assertSentTo() and this assertion also fails because the notification is in failed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question