Take a look at this part of the documentation: https://laravel.com/docs/master/testing#mocking
Jul 20, 2016
3
Level 2
How to fire event in integration test?
I'm trying fire even in my integration test but it does not triggering. I set up QUEUE_DRIVER=sync in my phpunit xml. Why event and listener is not working ? The workflow of my app is next:
Create some entity. Send it to remote server (i use even and listener); Give back some id and write it to db.
public function testCanGetCbdOfPlan() {
$plan = factory(Plan::class)->create();
$plan->save();
Event::fire(new PlanSaveEvent($plan));
//
$this->assertNotEmpty($plan->cbd_id, 'CBD_ID is empty');
}
Level 88
To be honest you shouldn't run a test that is communicating with another server at all! What happens when the server is down? Your tests will always fail!
Apart from that. I think you should mock the results of the listeners or simply call the listeners directly.
1 like
Please or to participate in this conversation.