Repository navigation
Expand file tree
/
Copy pathQueueManagerTest.php
More file actions
executable file
·152 lines (120 loc) · 4.61 KB
/
Copy pathQueueManagerTest.php
File metadata and controls
executable file
·152 lines (120 loc) · 4.61 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Illuminate\Tests\Queue;
use Illuminate\Container\Container;
use Illuminate\Encryption\Encrypter;
use Illuminate\Queue\Connectors\SyncConnector;
use Illuminate\Queue\Queue;
use Illuminate\Queue\QueueManager;
use Illuminate\Queue\SyncQueue;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
class QueueManagerTest extends TestCase
{
protected function tearDown(): void
{
Queue::createPayloadUsing(null);
}
public function testDefaultConnectionCanBeResolved()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
];
$app['encrypter'] = new Encrypter(str_repeat('a', 16));
$manager = new QueueManager($app);
$manager->addConnector('sync', fn () => new SyncConnector);
$queue = $manager->connection('sync');
$this->assertInstanceOf(SyncQueue::class, $queue);
$this->assertSame('sync', $queue->getConnectionName());
$this->assertSame($app, $queue->getContainer());
}
public function testOtherConnectionCanBeResolved()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'sync',
'queue.connections.foo' => ['driver' => 'bar'],
];
$app['encrypter'] = new Encrypter(str_repeat('a', 16));
$manager = new QueueManager($app);
$manager->addConnector('bar', fn () => new SyncConnector);
$queue = $manager->connection('foo');
$this->assertInstanceOf(SyncQueue::class, $queue);
$this->assertSame('foo', $queue->getConnectionName());
$this->assertSame($app, $queue->getContainer());
}
public function testNullConnectionCanBeResolved()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'null',
];
$app['encrypter'] = new Encrypter(str_repeat('a', 16));
$manager = new QueueManager($app);
$manager->addConnector('null', fn () => new SyncConnector);
$queue = $manager->connection('null');
$this->assertInstanceOf(SyncQueue::class, $queue);
$this->assertSame('null', $queue->getConnectionName());
$this->assertSame($app, $queue->getContainer());
}
public function testEnumConnectionCanBeResolved()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
];
$app['encrypter'] = new Encrypter(str_repeat('a', 16));
$manager = new QueueManager($app);
$manager->addConnector('sync', fn () => new SyncConnector);
$queue = $manager->connection(QueueConnectionName::Sync);
$this->assertInstanceOf(SyncQueue::class, $queue);
$this->assertSame('sync', $queue->getConnectionName());
$this->assertSame($app, $queue->getContainer());
}
public function testEnumConnectionCanBeChecked()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
];
$app['encrypter'] = new Encrypter(str_repeat('a', 16));
$manager = new QueueManager($app);
$manager->addConnector('sync', fn () => new SyncConnector);
$this->assertFalse($manager->connected(QueueConnectionName::Sync));
$manager->connection(QueueConnectionName::Sync);
$this->assertTrue($manager->connected(QueueConnectionName::Sync));
}
public function testCreatePayloadUsingDoesNotResolveTheDefaultConnection()
{
$app = new Container;
$app['config'] = [
'queue.default' => 'cloud',
];
$manager = new QueueManager($app);
$manager->createPayloadUsing(function ($connection, $queue, $payload) {
return ['foo' => 'bar'];
});
$this->assertFalse($manager->connected('cloud'));
$callbacks = (new ReflectionProperty(Queue::class, 'createPayloadCallbacks'))->getValue();
$this->assertSame(['foo' => 'bar'], $callbacks[array_key_last($callbacks)](null, null, null));
}
public function testSetDefaultDriverAcceptsBackedEnum()
{
$app = [
'config' => [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
],
];
$manager = new QueueManager($app);
$manager->setDefaultDriver(QueueConnectionName::Sync);
$this->assertSame('sync', $app['config']['queue.default']);
}
}
enum QueueConnectionName: string
{
case Sync = 'sync';
}