Testing listeners with Queue::fake()

前端 未结 2 613
闹比i
闹比i 2021-02-12 22:21

My Laravel 5.5 application has a Product model. The Product model has a dispatchesEvents property that looks like this:

/*         


        
2条回答
  •  我寻月下人不归
    2021-02-12 23:01

    The problem here is that the listener is not the job pushed to the queue. Instead, there's a Illuminate\Events\CallQueuedListener job that is queued and will in turn call the appropriate listener when resolved.

    So you could do your assertion like this:

    Queue::assertPushed(CallQueuedListener::class, function ($job) {
        return $job->class == CreateProductInMagento::class;
    });
    

提交回复
热议问题