我的Laravel 5.5应用程序有Product
个型号.Product
型号的dispatchesEvents
属性如下所示:
/**
* The event map for the model.
*
* @var array
*/
protected $dispatchesEvents = [
'created' => ProductCreated::class,
'updated' => ProductUpdated::class,
'deleted' => ProductDeleted::class
];
我还有一个名为CreateProductInMagento
的侦听器,它映射到EventServiceProvider
中的ProductCreated
事件.此侦听器实现ShouldQueue
接口.
When a product is created, the ProductCreated
event is fired and the CreateProductInMagento
listener is pushed to the queue and is run.
我现在正试图为所有这些内容编写一个测试.这是我所拥有的:
/** @test */
public function a_created_product_is_pushed_to_the_queue_so_it_can_be_added_to_magento()
{
Queue::fake();
factory(Product::class)->create();
Queue::assertPushed(CreateProductInMagento::class);
}
但我收到一条The expected [App\Listeners\Magento\Product\CreateProductInMagento] job was not pushed.
的错误信息.
How do I test queueable listeners using Laravel's 100 method?