From b855e0df43f916974d335621afb624f0b6b178c1 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Wed, 23 Oct 2024 16:32:32 +0100 Subject: [PATCH] add test --- tests/Integration/Queue/WorkCommandTest.php | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Integration/Queue/WorkCommandTest.php b/tests/Integration/Queue/WorkCommandTest.php index 7d1d5ef12121..06a7378e0a23 100644 --- a/tests/Integration/Queue/WorkCommandTest.php +++ b/tests/Integration/Queue/WorkCommandTest.php @@ -3,12 +3,18 @@ namespace Illuminate\Tests\Integration\Queue; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Queue\Worker; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Exceptions; use Illuminate\Support\Facades\Queue; use Orchestra\Testbench\Attributes\WithMigration; +use RuntimeException; #[WithMigration] #[WithMigration('queue')] @@ -157,6 +163,19 @@ public function testMaxTimeExceeded() $this->assertFalse(FirstJob::$ran); $this->assertFalse(SecondJob::$ran); } + + public function testFailedJobListenerOnlyRunsOnce() + { + Exceptions::fake(); + + Queue::push(new FirstJob); + $this->artisan('queue:work', ['--once' => true])->assertExitCode(0); + + Queue::push(new JobWillFail); + $this->withoutMockingConsoleOutput()->artisan('queue:work', ['--once' => true]); + Exceptions::assertNotReported(UniqueConstraintViolationException::class); + $this->assertSame(2, substr_count(Artisan::output(), JobWillFail::class)); + } } class FirstJob implements ShouldQueue @@ -196,3 +215,13 @@ public function handle() static::$ran = true; } } + +class JobWillFail implements ShouldQueue +{ + use Dispatchable, Queueable; + + public function handle() + { + throw new RuntimeException; + } +}