Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bytestream committed Oct 23, 2024
1 parent ff22f3a commit b855e0d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Integration/Queue/WorkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -196,3 +215,13 @@ public function handle()
static::$ran = true;
}
}

class JobWillFail implements ShouldQueue
{
use Dispatchable, Queueable;

public function handle()
{
throw new RuntimeException;
}
}

0 comments on commit b855e0d

Please sign in to comment.