1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\QueueBundle\Tests; |
4
|
|
|
|
5
|
|
|
require_once __DIR__.'/TestKernel.php'; |
6
|
|
|
|
7
|
|
|
use Bdf\Queue\Connection\Prime\PrimeConnection; |
|
|
|
|
8
|
|
|
use Bdf\Queue\Console\Command\BindCommand; |
9
|
|
|
use Bdf\Queue\Console\Command\ConsumeCommand; |
10
|
|
|
use Bdf\Queue\Console\Command\Failer\AbstractFailerCommand; |
11
|
|
|
use Bdf\Queue\Console\Command\Failer\DeleteCommand; |
12
|
|
|
use Bdf\Queue\Console\Command\Failer\FlushCommand; |
13
|
|
|
use Bdf\Queue\Console\Command\Failer\ForgetCommand; |
14
|
|
|
use Bdf\Queue\Console\Command\Failer\RetryCommand; |
15
|
|
|
use Bdf\Queue\Console\Command\Failer\ShowCommand; |
16
|
|
|
use Bdf\Queue\Console\Command\InfoCommand; |
17
|
|
|
use Bdf\Queue\Console\Command\ProduceCommand; |
18
|
|
|
use Bdf\Queue\Console\Command\SetupCommand; |
19
|
|
|
use Bdf\Queue\Consumer\Receiver\Builder\ReceiverLoaderInterface; |
20
|
|
|
use Bdf\Queue\Destination\DestinationInterface; |
21
|
|
|
use Bdf\Queue\Destination\DestinationManager; |
22
|
|
|
use Bdf\Queue\Failer\FailedJobStorageInterface; |
23
|
|
|
use Bdf\Queue\Failer\MemoryFailedJobRepository; |
24
|
|
|
use Bdf\Queue\Message\Message; |
25
|
|
|
use Bdf\Queue\Message\QueuedMessage; |
26
|
|
|
use Bdf\Queue\Testing\QueueHelper; |
27
|
|
|
use Bdf\QueueBundle\BdfQueueBundle; |
28
|
|
|
use Bdf\QueueBundle\Consumption\ReceiverLoader; |
29
|
|
|
use Bdf\QueueBundle\Tests\Fixtures\TestHandler; |
30
|
|
|
use PHPUnit\Framework\TestCase; |
31
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
32
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* BdfSerializerBundleTest |
36
|
|
|
*/ |
37
|
|
|
class BdfQueueBundleTest extends TestCase |
38
|
|
|
{ |
39
|
|
|
public function test_default_config() |
40
|
|
|
{ |
41
|
|
|
$builder = $this->createMock(ContainerBuilder::class); |
42
|
|
|
|
43
|
|
|
$bundle = new BdfQueueBundle(); |
44
|
|
|
|
45
|
|
|
$this->assertNull($bundle->build($builder)); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
*/ |
51
|
|
|
public function test_kernel() |
52
|
|
|
{ |
53
|
|
|
$kernel = new \TestKernel(); |
54
|
|
|
$kernel->boot(); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf(DestinationManager::class, $kernel->getContainer()->get('bdf_queue.destination_manager')); |
57
|
|
|
$this->assertSame($kernel->getContainer()->get('bdf_queue.destination_manager'), $kernel->getContainer()->get(DestinationManager::class)); |
58
|
|
|
$this->assertInstanceOf(ReceiverLoader::class, $kernel->getContainer()->get('bdf_queue.receiver.loader')); |
59
|
|
|
$this->assertInstanceOf(ReceiverLoader::class, $kernel->getContainer()->get(ReceiverLoaderInterface::class)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
public function test_functional() |
66
|
|
|
{ |
67
|
|
|
$kernel = new \TestKernel(__DIR__.'/Fixtures/conf_functional.yaml'); |
68
|
|
|
$kernel->boot(); |
69
|
|
|
|
70
|
|
|
/** @var DestinationManager $destinations */ |
71
|
|
|
$destinations = $kernel->getContainer()->get('bdf_queue.destination_manager'); |
72
|
|
|
$destination = $destinations->create('test'); |
73
|
|
|
|
74
|
|
|
$this->assertInstanceOf(DestinationInterface::class, $destination); |
75
|
|
|
|
76
|
|
|
/** @var TestHandler $handler */ |
77
|
|
|
$handler = $kernel->getContainer()->get(TestHandler::class); |
78
|
|
|
|
79
|
|
|
$helper = new QueueHelper($kernel->getContainer()); |
80
|
|
|
$destination->send(new Message(['foo' => 'bar'])); |
81
|
|
|
|
82
|
|
|
$helper->consume(1, 'test'); |
83
|
|
|
$this->assertEquals([['foo' => 'bar']], $handler->messages); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
*/ |
89
|
|
|
public function test_with_json_serializer() |
90
|
|
|
{ |
91
|
|
|
$kernel = new \TestKernel(__DIR__.'/Fixtures/conf_with_json_serializer.yaml'); |
92
|
|
|
$kernel->boot(); |
93
|
|
|
|
94
|
|
|
/** @var DestinationManager $destinations */ |
95
|
|
|
$destinations = $kernel->getContainer()->get('bdf_queue.destination_manager'); |
96
|
|
|
$destination = $destinations->create('test'); |
97
|
|
|
|
98
|
|
|
$this->assertInstanceOf(DestinationInterface::class, $destination); |
99
|
|
|
|
100
|
|
|
/** @var TestHandler $handler */ |
101
|
|
|
$handler = $kernel->getContainer()->get(TestHandler::class); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$helper = new QueueHelper($kernel->getContainer()); |
104
|
|
|
$destination->send(new Message(new class implements \JsonSerializable { |
105
|
|
|
public function jsonSerialize() |
106
|
|
|
{ |
107
|
|
|
return ['foo' => 'bar']; |
108
|
|
|
} |
109
|
|
|
})); |
110
|
|
|
|
111
|
|
|
/** @var QueuedMessage $message */ |
112
|
|
|
$message = $helper->peek(1, 'test')[0]; |
113
|
|
|
|
114
|
|
|
$this->assertEquals( |
115
|
|
|
'{"data":{"foo":"bar"},"queuedAt":' . json_encode($message->queuedAt()) . '}', |
116
|
|
|
$message->raw() |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
*/ |
123
|
|
|
public function test_connection_options() |
124
|
|
|
{ |
125
|
|
|
$kernel = new \TestKernel(); |
126
|
|
|
$kernel->boot(); |
127
|
|
|
|
128
|
|
|
$configs = $kernel->getContainer()->getParameter('bdf_queue.connections'); |
129
|
|
|
|
130
|
|
|
$this->assertEquals([ |
131
|
|
|
'gearman' => [ |
132
|
|
|
'driver' => null, |
133
|
|
|
'host' => null, |
134
|
|
|
'serializer' => ['id' => 'native'], |
135
|
|
|
'queue' => null, |
136
|
|
|
'url' => 'gearman://127.0.0.1', |
137
|
|
|
'options' => ['client_timeout' => 1], |
138
|
|
|
'vendor' => null, |
139
|
|
|
'port' => null, |
140
|
|
|
'user' => null, |
141
|
|
|
'password' => null, |
142
|
|
|
'connection_factory' => null, |
143
|
|
|
] |
144
|
|
|
], $configs); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* |
149
|
|
|
*/ |
150
|
|
|
public function test_destination_options() |
151
|
|
|
{ |
152
|
|
|
$kernel = new \TestKernel(); |
153
|
|
|
$kernel->boot(); |
154
|
|
|
|
155
|
|
|
$configs = $kernel->getContainer()->getParameter('bdf_queue.destinations'); |
156
|
|
|
|
157
|
|
|
$this->assertEquals([ |
158
|
|
|
'b2p_bus' => 'queue://gearman/b2p_bus', |
159
|
|
|
'custom_bus' => 'queue://gearman/custom_bus', |
160
|
|
|
], $configs); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* |
165
|
|
|
*/ |
166
|
|
|
public function test_commands() |
167
|
|
|
{ |
168
|
|
|
$kernel = new \TestKernel(); |
169
|
|
|
$kernel->boot(); |
170
|
|
|
$console = new Application($kernel); |
171
|
|
|
|
172
|
|
|
$this->assertInstanceOf(BindCommand::class, $console->get('queue:bind')); |
173
|
|
|
$this->assertInstanceOf(ConsumeCommand::class, $console->get('queue:consume')); |
174
|
|
|
$this->assertInstanceOf(InfoCommand::class, $console->get('queue:info')); |
175
|
|
|
$this->assertInstanceOf(ProduceCommand::class, $console->get('queue:produce')); |
176
|
|
|
$this->assertInstanceOf(SetupCommand::class, $console->get('queue:setup')); |
177
|
|
|
|
178
|
|
|
$this->assertInstanceOf(DeleteCommand::class, $console->get('queue:failer:delete')); |
179
|
|
|
$this->assertInstanceOf(RetryCommand::class, $console->get('queue:failer:retry')); |
180
|
|
|
$this->assertInstanceOf(ShowCommand::class, $console->get('queue:failer:show')); |
181
|
|
|
$this->assertInstanceOf(FlushCommand::class, $console->get('queue:failer:flush')); |
182
|
|
|
$this->assertInstanceOf(ForgetCommand::class, $console->get('queue:failer:forget')); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return void |
187
|
|
|
*/ |
188
|
|
|
public function test_failer() |
189
|
|
|
{ |
190
|
|
|
$kernel = new \TestKernel(); |
191
|
|
|
$kernel->boot(); |
192
|
|
|
$console = new Application($kernel); |
193
|
|
|
|
194
|
|
|
$command = $console->get('queue:failer:delete'); |
195
|
|
|
|
196
|
|
|
$r = new \ReflectionProperty(AbstractFailerCommand::class, 'repository'); |
197
|
|
|
$r->setAccessible(true); |
198
|
|
|
|
199
|
|
|
/** @var FailedJobStorageInterface $failer */ |
200
|
|
|
$failer = $r->getValue($command); |
201
|
|
|
|
202
|
|
|
$this->assertInstanceOf(MemoryFailedJobRepository::class, $failer); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function test_custom_failer() |
209
|
|
|
{ |
210
|
|
|
$kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_custom_failer.yaml'); |
211
|
|
|
$kernel->boot(); |
212
|
|
|
$console = new Application($kernel); |
213
|
|
|
|
214
|
|
|
$command = $console->get('queue:failer:delete'); |
215
|
|
|
|
216
|
|
|
$r = new \ReflectionProperty(AbstractFailerCommand::class, 'repository'); |
217
|
|
|
$r->setAccessible(true); |
218
|
|
|
|
219
|
|
|
/** @var FailedJobStorageInterface $failer */ |
220
|
|
|
$failer = $r->getValue($command); |
221
|
|
|
|
222
|
|
|
$this->assertInstanceOf(MemoryFailedJobRepository::class, $failer); |
223
|
|
|
$this->assertSame($failer, $kernel->getContainer()->get('foo')); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* |
228
|
|
|
*/ |
229
|
|
|
public function test_prime_connection() |
230
|
|
|
{ |
231
|
|
|
if (class_exists(PrimeConnection::class)) { |
232
|
|
|
$this->markTestSkipped('b2pweb/bdf-queue-prime-adapter installed'); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$this->expectException(\LogicException::class); |
236
|
|
|
|
237
|
|
|
$kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_prime_connection.yaml'); |
238
|
|
|
$kernel->boot(); |
239
|
|
|
|
240
|
|
|
/** @var DestinationManager $destinations */ |
241
|
|
|
$destinations = $kernel->getContainer()->get('bdf_queue.destination_manager'); |
242
|
|
|
$destinations->queue('prime', 'queue_name'); |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths