-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathQueueableTest.php
85 lines (70 loc) · 2.13 KB
/
QueueableTest.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Illuminate\Tests\Bus;
use Illuminate\Bus\Queueable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class QueueableTest extends TestCase
{
public static function connectionDataProvider(): array
{
return [
'uses string' => ['redis', 'redis'],
'uses BackedEnum #1' => [ConnectionEnum::SQS, 'sqs'],
'uses BackedEnum #2' => [ConnectionEnum::REDIS, 'redis'],
'uses null' => [null, null],
];
}
#[DataProvider('connectionDataProvider')]
public function testOnConnection(mixed $connection, ?string $expected): void
{
$job = new FakeJob();
$job->onConnection($connection);
$this->assertSame($job->connection, $expected);
}
#[DataProvider('connectionDataProvider')]
public function testAllOnConnection(mixed $connection, ?string $expected): void
{
$job = new FakeJob();
$job->allOnConnection($connection);
$this->assertSame($job->connection, $expected);
$this->assertSame($job->chainConnection, $expected);
}
public static function queuesDataProvider(): array
{
return [
'uses string' => ['high', 'high'],
'uses BackedEnum #1' => [QueueEnum::DEFAULT, 'default'],
'uses BackedEnum #2' => [QueueEnum::HIGH, 'high'],
'uses null' => [null, null],
];
}
#[DataProvider('queuesDataProvider')]
public function testOnQueue(mixed $queue, ?string $expected): void
{
$job = new FakeJob();
$job->onQueue($queue);
$this->assertSame($job->queue, $expected);
}
#[DataProvider('queuesDataProvider')]
public function testAllOnQueue(mixed $queue, ?string $expected): void
{
$job = new FakeJob();
$job->allOnQueue($queue);
$this->assertSame($job->queue, $expected);
$this->assertSame($job->chainQueue, $expected);
}
}
class FakeJob
{
use Queueable;
}
enum ConnectionEnum: string
{
case SQS = 'sqs';
case REDIS = 'redis';
}
enum QueueEnum: string
{
case HIGH = 'high';
case DEFAULT = 'default';
}