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