Created
May 21, 2020 13:48
-
-
Save owenconti/ac02f0fb91260ab76c7ac18b875bb18e to your computer and use it in GitHub Desktop.
Faking the Queue in Laravel tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @test */ | |
public function it_fails_attach_volume_to_instance_if_volume_is_not_in_provisioning_state() { | |
Event::fake([JobFailed::class]); | |
$queue = Queue::getFacadeRoot(); | |
Queue::fake(); | |
$volume = VolumeFactory::make()->pending()->create(); | |
Queue::swap($queue); | |
AttachVolumeToInstance::dispatch($volume); | |
Event::assertDispatched(JobFailed::class, function ($event) { | |
return $event->exception->getMessage() === 'Volume is not in Provisioning state.'; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @test */ | |
public function it_fails_attach_volume_to_instance_if_volume_is_not_in_provisioning_state() | |
{ | |
// Given | |
Event::fake([JobFailed::class]); | |
$volume = null; | |
QueueFake::wrap(function () use (&$volume) { | |
$volume = VolumeFactory::make()->pending()->create(); | |
}); | |
// When | |
AttachVolumeToInstance::dispatch($volume); | |
// Then | |
Event::assertDispatched(JobFailed::class, function ($event) { | |
return $event->exception->getMessage() === 'Volume is not in Provisioning state.'; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment