Running artisan queue:work will not solve the problem, because when testing Laravel is configured to use the sync driver, which simply runs tasks synchronously in your tests. I am not sure why the work is not being pushed, although I would suggest that this is due to the fact that Laravel handles events differently in tests. Regardless of whether there is a better approach you can take to write your own tests, which should both fix the problem and make your code more extensible.
In your ProductTest , instead of testing this a_created_product_is_pushed_to_the_queue_so_it_can_be_added_to_magento , you should just check that the event is fired. Your ProductTest doesn't care what a ProductCreated event is; this is a ProductCreatedTest task. Thus, you can use Event Faking to slightly modify the test:
public function product_created_event_is_fired_upon_creation() { Event::fake(); factory(Product::class)->create(); Event::assertDispatched(ProductCreated::class); }
Then create a new ProductCreatedTest to unit test your ProductCreated event. Here you should put the statement that the job is queued:
public function create_product_in_magento_job_is_pushed() { Queue::fake();
This has the added benefit of making your code easier to change in the future, since your tests now more closely monitor the practice of only testing the class for which they are responsible. In addition, it should solve the problem that you encounter when events released from the model are not waiting for your assignments.
source share