Skip to content

Instantly share code, notes, and snippets.

@owenconti
Created May 21, 2020 13:48
Show Gist options
  • Save owenconti/ac02f0fb91260ab76c7ac18b875bb18e to your computer and use it in GitHub Desktop.
Save owenconti/ac02f0fb91260ab76c7ac18b875bb18e to your computer and use it in GitHub Desktop.
Faking the Queue in Laravel tests
<?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.';
});
}
<?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