|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 6 | +use Illuminate\Foundation\Bus\Dispatchable; |
| 7 | +use Illuminate\Foundation\Queue\Queueable; |
| 8 | +use Illuminate\Support\Facades\Queue; |
| 9 | +use PHPUnit\Framework\Attributes\Test; |
| 10 | +use Tests\TestCase; |
| 11 | +use Illuminate\Support\Facades\Config; |
| 12 | +use Illuminate\Support\Facades\Bus; |
| 13 | + |
| 14 | +class SqsDispatchOverrideTest extends TestCase |
| 15 | +{ |
| 16 | + #[Test] |
| 17 | + public function it_forces_default_queue_when_using_sqs() |
| 18 | + { |
| 19 | + // Simulate SQS connection |
| 20 | + Config::set('queue.default', 'sqs'); |
| 21 | + |
| 22 | + Queue::fake(); |
| 23 | + |
| 24 | + // Dispatch a job with a custom queue name |
| 25 | + FakeJob::dispatch()->onQueue('bpmn'); |
| 26 | + |
| 27 | + // Assert the job was dispatched to the forced queue (default) |
| 28 | + Queue::assertPushed(FakeJob::class, function ($job) { |
| 29 | + return $job->queue === null; |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + #[Test] |
| 34 | + public function it_respects_original_queue_when_not_using_sqs() |
| 35 | + { |
| 36 | + // Simulate Redis connection |
| 37 | + Config::set('queue.default', 'redis'); |
| 38 | + |
| 39 | + Bus::fake(); |
| 40 | + |
| 41 | + // Dispatch a job with a custom queue name |
| 42 | + FakeJob::dispatch()->onQueue('bpmn'); |
| 43 | + |
| 44 | + Bus::assertDispatched(FakeJob::class, function ($job) { |
| 45 | + return $job->queue === 'bpmn'; |
| 46 | + }); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class FakeJob implements ShouldQueue |
| 51 | +{ |
| 52 | + use Dispatchable, Queueable; |
| 53 | + |
| 54 | + public function handle(): void |
| 55 | + { |
| 56 | + \Log::info("TestJob executed successfully."); |
| 57 | + } |
| 58 | +} |
0 commit comments