Replies: 2 comments
-
@calebdw I'm finding that I'm agreeing with your perspective here, using I used the following code to remove the event listeners I wasn't interested in testing, can anyone explain why this might be a bad idea or perhaps the approach is ok?
|
Beta Was this translation helpful? Give feedback.
-
This is definitely a bug, as if we read the documentation https://laravel.com/docs/9.x/mocking#queue-fake, we should be able to use our listener directly without having to go through the hack with Also, the current code prevents completely the use of the I've made the fix here: |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
9.52.x
PHP Version
8.1.x
Database Driver & Version
Postgres 14
Description
Hello!
It is very non-trivial to test Listeners with QueueFake at the moment; mostly because the Listeners are inside the
CallQueuedListener
job.Therefore, asserting whether or not a Listener was pushed requires something like:
which either requires duplicated code or a custom function (which is not ideal).
The issue I'm running into at the moment is that I have several Listeners listening to a specific Event, and I want to fake all but one of them (the one I'm currently testing). However, doing the following does not work:
as everything is faked because
<listener>
is not an actual job---I'm not sure if it's possible to actually fake a listener without overridingQueueFake::shouldDispatchJob()
.All in all, it would be very helpful to include first class testing support for Listeners just like with Jobs.
Thanks!
Steps To Reproduce
n/a
Beta Was this translation helpful? Give feedback.
All reactions