illia's avatar
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');
    }
0 likes
3 replies
illia's avatar
Level 2

@bobbybouwmann it won't work because I need to fire real event with data (\App\Mode\Plan) in it so that PlanSaveListener will be able to make request using Guzzle.

bobbybouwmann's avatar
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.