In a certain observer class, I've got this code
//Just for context
public function updated () {
Artisan::queue('campaign:resume', ['campaignId' => $campaign->id]);
}
The purpose is to test that the command is indeed queued when the conditions met. I've tried several approaches but as far as I can tell, Queue::fake() doesn't affect the queue method and can't seem to find a way to use Bus::fake to assert this queued command.
This is what I've tested and commented is what I've tried. Again, the content of the Observer is simplified as it doesn't matter.
public function testSomeClassShouldQueueACommand() {
//Arrange
//Queue::fake();
//$fakeBus = Bus::fake();
$campaignObserver = new CampaignObserver();
//$this->app->instance(\Illuminate\Foundation\Bus\PendingDispatch::class, $fakeBus);
//Act
$campaignObserver->updated();
//Assert
//Bus::assertDispatched('campaign:resume');
//Queue::assertPushed('campaign:resume');
//Artisan::shouldReceive('queue')->with('campaign:resume');
}
I've seen posts where some say: Just pass it to a job or an event and use Queue::fake/Event::fake.
It's contents aren't something that should be in a Job nor an Event. It doesn't make sense to create a class to handle "queue" of a command if the Artisan can handle queues itself.
Any ideas on how to complete this unit test?