diff --git a/app/Console/Commands/QueueHealth.php b/app/Console/Commands/QueueHealth.php index e797384..1c4cedc 100644 --- a/app/Console/Commands/QueueHealth.php +++ b/app/Console/Commands/QueueHealth.php @@ -73,7 +73,7 @@ public function handle() return 1; } - echo "The queue has $queueSize items, and is processing."; + $this->line("The queue has $queueSize items, and is processing."); return 0; } diff --git a/tests/Feature/QueueHealthTest.php b/tests/Feature/QueueHealthTest.php new file mode 100644 index 0000000..9cadcd1 --- /dev/null +++ b/tests/Feature/QueueHealthTest.php @@ -0,0 +1,43 @@ +createMock(\Illuminate\Contracts\Queue\Queue::class); + $mock->method('size')->willReturn(0); + $this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock); + + $this->artisan('queue:health')->assertExitCode(0); + } + + /** @test */ + function queue_is_healthy_when_a_job_was_recently_processed() + { + Cache::forever('queue.job.last-processed', \Carbon\Carbon::now()); + + $mock = $this->createMock(\Illuminate\Contracts\Queue\Queue::class); + $mock->method('size')->willReturn(1); + $this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock); + + $this->artisan('queue:health')->assertExitCode(0); + } + + /** @test */ + function queue_is_unhealthy_when_a_job_was_not_recently_processed() + { + Cache::forever('queue.job.last-processed', \Carbon\Carbon::now()->subHour()); + + $mock = $this->createMock(\Illuminate\Contracts\Queue\Queue::class); + $mock->method('size')->willReturn(1); + $this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock); + + $this->artisan('queue:health')->assertExitCode(1); + } +}