1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
7
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
8
|
|
|
use Symfony\Component\Config\FileLocator; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
10
|
|
|
use OldSound\RabbitMqBundle\DependencyInjection\OldSoundRabbitMqExtension; |
11
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class OldSoundRabbitMqExtensionTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testFooConnectionDefinition() |
17
|
|
|
{ |
18
|
|
|
$container = $this->getContainer('test.yml'); |
19
|
|
|
|
20
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.foo_connection')); |
21
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.connection.foo_connection'); |
22
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.foo_connection')); |
23
|
|
|
$factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.foo_connection'); |
24
|
|
|
$this->assertEquals(array('old_sound_rabbit_mq.connection_factory.foo_connection', 'createConnection'), $definition->getFactory()); |
25
|
|
|
$this->assertEquals(array( |
26
|
|
|
'host' => 'foo_host', |
27
|
|
|
'port' => 123, |
28
|
|
|
'user' => 'foo_user', |
29
|
|
|
'password' => 'foo_password', |
30
|
|
|
'vhost' => '/foo', |
31
|
|
|
'lazy' => false, |
32
|
|
|
'connection_timeout' => 3, |
33
|
|
|
'read_write_timeout' => 3, |
34
|
|
|
'ssl_context' => array(), |
35
|
|
|
'keepalive' => false, |
36
|
|
|
'heartbeat' => 0, |
37
|
|
|
'use_socket' => false, |
38
|
|
|
'url' => '', |
39
|
|
|
), $factory->getArgument(1)); |
40
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testSslConnectionDefinition() |
44
|
|
|
{ |
45
|
|
|
$container = $this->getContainer('test.yml'); |
46
|
|
|
|
47
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.ssl_connection')); |
48
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.connection.ssl_connection'); |
49
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.ssl_connection')); |
50
|
|
|
$factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.ssl_connection'); |
51
|
|
|
$this->assertEquals(array('old_sound_rabbit_mq.connection_factory.ssl_connection', 'createConnection'), $definition->getFactory()); |
52
|
|
|
$this->assertEquals(array( |
53
|
|
|
'host' => 'ssl_host', |
54
|
|
|
'port' => 123, |
55
|
|
|
'user' => 'ssl_user', |
56
|
|
|
'password' => 'ssl_password', |
57
|
|
|
'vhost' => '/ssl', |
58
|
|
|
'lazy' => false, |
59
|
|
|
'connection_timeout' => 3, |
60
|
|
|
'read_write_timeout' => 3, |
61
|
|
|
'ssl_context' => array( |
62
|
|
|
'verify_peer' => false, |
63
|
|
|
), |
64
|
|
|
'keepalive' => false, |
65
|
|
|
'heartbeat' => 0, |
66
|
|
|
'use_socket' => false, |
67
|
|
|
'url' => '', |
68
|
|
|
), $factory->getArgument(1)); |
69
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testLazyConnectionDefinition() |
73
|
|
|
{ |
74
|
|
|
$container = $this->getContainer('test.yml'); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_connection')); |
77
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_connection'); |
78
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_connection')); |
79
|
|
|
$factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.lazy_connection'); |
80
|
|
|
$this->assertEquals(array('old_sound_rabbit_mq.connection_factory.lazy_connection', 'createConnection'), $definition->getFactory()); |
81
|
|
|
$this->assertEquals(array( |
82
|
|
|
'host' => 'lazy_host', |
83
|
|
|
'port' => 456, |
84
|
|
|
'user' => 'lazy_user', |
85
|
|
|
'password' => 'lazy_password', |
86
|
|
|
'vhost' => '/lazy', |
87
|
|
|
'lazy' => true, |
88
|
|
|
'connection_timeout' => 3, |
89
|
|
|
'read_write_timeout' => 3, |
90
|
|
|
'ssl_context' => array(), |
91
|
|
|
'keepalive' => false, |
92
|
|
|
'heartbeat' => 0, |
93
|
|
|
'use_socket' => false, |
94
|
|
|
'url' => '', |
95
|
|
|
), $factory->getArgument(1)); |
96
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.lazy.connection.class%', $definition->getClass()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testDefaultConnectionDefinition() |
100
|
|
|
{ |
101
|
|
|
$container = $this->getContainer('test.yml'); |
102
|
|
|
|
103
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.default')); |
104
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.connection.default'); |
105
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.default')); |
106
|
|
|
$factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.default'); |
107
|
|
|
$this->assertEquals(array('old_sound_rabbit_mq.connection_factory.default', 'createConnection'), $definition->getFactory()); |
108
|
|
|
$this->assertEquals(array( |
109
|
|
|
'host' => 'localhost', |
110
|
|
|
'port' => 5672, |
111
|
|
|
'user' => 'guest', |
112
|
|
|
'password' => 'guest', |
113
|
|
|
'vhost' => '/', |
114
|
|
|
'lazy' => false, |
115
|
|
|
'connection_timeout' => 3, |
116
|
|
|
'read_write_timeout' => 3, |
117
|
|
|
'ssl_context' => array(), |
118
|
|
|
'keepalive' => false, |
119
|
|
|
'heartbeat' => 0, |
120
|
|
|
'use_socket' => false, |
121
|
|
|
'url' => '', |
122
|
|
|
), $factory->getArgument(1)); |
123
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testSocketConnectionDefinition() |
127
|
|
|
{ |
128
|
|
|
$container = $this->getContainer('test.yml'); |
129
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.socket_connection')); |
130
|
|
|
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.socket_connection'); |
131
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.socket_connection')); |
132
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.socket_connection.class%', $definiton->getClass()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testLazySocketConnectionDefinition() |
136
|
|
|
{ |
137
|
|
|
$container = $this->getContainer('test.yml'); |
138
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_socket')); |
139
|
|
|
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_socket'); |
140
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_socket')); |
141
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.lazy.socket_connection.class%', $definiton->getClass()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testFooBinding() |
145
|
|
|
{ |
146
|
|
|
$container = $this->getContainer('test.yml'); |
147
|
|
|
$binding = array( |
148
|
|
|
'arguments' => null, |
149
|
|
|
'class' => '%old_sound_rabbit_mq.binding.class%', |
150
|
|
|
'connection' => 'default', |
151
|
|
|
'exchange' => 'foo', |
152
|
|
|
'destination' => 'bar', |
153
|
|
|
'destination_is_exchange' => false, |
154
|
|
|
'nowait' => false, |
155
|
|
|
'routing_key' => 'baz', |
156
|
|
|
); |
157
|
|
|
ksort($binding); |
158
|
|
|
$key = md5(json_encode($binding)); |
159
|
|
|
$name = sprintf('old_sound_rabbit_mq.binding.%s', $key); |
160
|
|
|
$this->assertTrue($container->has($name)); |
161
|
|
|
$definition = $container->getDefinition($name); |
162
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
163
|
|
|
$this->assertBindingMethodCalls($definition, $binding); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testMooBinding() |
167
|
|
|
{ |
168
|
|
|
$container = $this->getContainer('test.yml'); |
169
|
|
|
$binding = array( |
170
|
|
|
'arguments' => array('moo' => 'cow'), |
171
|
|
|
'class' => '%old_sound_rabbit_mq.binding.class%', |
172
|
|
|
'connection' => 'default2', |
173
|
|
|
'exchange' => 'moo', |
174
|
|
|
'destination' => 'cow', |
175
|
|
|
'destination_is_exchange' => true, |
176
|
|
|
'nowait' => true, |
177
|
|
|
'routing_key' => null, |
178
|
|
|
); |
179
|
|
|
ksort($binding); |
180
|
|
|
$key = md5(json_encode($binding)); |
181
|
|
|
$name = sprintf('old_sound_rabbit_mq.binding.%s', $key); |
182
|
|
|
$this->assertTrue($container->has($name)); |
183
|
|
|
$definition = $container->getDefinition($name); |
184
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default2'); |
185
|
|
|
$this->assertBindingMethodCalls($definition, $binding); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
protected function assertBindingMethodCalls(Definition $definition, $binding) |
189
|
|
|
{ |
190
|
|
|
$this->assertEquals(array( |
191
|
|
|
array( |
192
|
|
|
'setArguments', |
193
|
|
|
array( |
194
|
|
|
$binding['arguments'] |
195
|
|
|
) |
196
|
|
|
), |
197
|
|
|
array( |
198
|
|
|
'setDestination', |
199
|
|
|
array( |
200
|
|
|
$binding['destination'] |
201
|
|
|
) |
202
|
|
|
), |
203
|
|
|
array( |
204
|
|
|
'setDestinationIsExchange', |
205
|
|
|
array( |
206
|
|
|
$binding['destination_is_exchange'] |
207
|
|
|
) |
208
|
|
|
), |
209
|
|
|
array( |
210
|
|
|
'setExchange', |
211
|
|
|
array( |
212
|
|
|
$binding['exchange'] |
213
|
|
|
) |
214
|
|
|
), |
215
|
|
|
array( |
216
|
|
|
'isNowait', |
217
|
|
|
array( |
218
|
|
|
$binding['nowait'] |
219
|
|
|
) |
220
|
|
|
), |
221
|
|
|
array( |
222
|
|
|
'setRoutingKey', |
223
|
|
|
array( |
224
|
|
|
$binding['routing_key'] |
225
|
|
|
) |
226
|
|
|
), |
227
|
|
|
), |
228
|
|
|
$definition->getMethodCalls() |
229
|
|
|
); |
230
|
|
|
} |
231
|
|
|
public function testFooProducerDefinition() |
232
|
|
|
{ |
233
|
|
|
$container = $this->getContainer('test.yml'); |
234
|
|
|
|
235
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
236
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_producer_producer'); |
237
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
238
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_producer'); |
239
|
|
|
$this->assertEquals(array( |
240
|
|
|
array( |
241
|
|
|
'setExchangeOptions', |
242
|
|
|
array( |
243
|
|
|
array( |
244
|
|
|
'name' => 'foo_exchange', |
245
|
|
|
'type' => 'direct', |
246
|
|
|
'passive' => true, |
247
|
|
|
'durable' => false, |
248
|
|
|
'auto_delete' => true, |
249
|
|
|
'internal' => true, |
250
|
|
|
'nowait' => true, |
251
|
|
|
'arguments' => null, |
252
|
|
|
'ticket' => null, |
253
|
|
|
'declare' => true, |
254
|
|
|
) |
255
|
|
|
) |
256
|
|
|
), |
257
|
|
|
array( |
258
|
|
|
'setQueueOptions', |
259
|
|
|
array( |
260
|
|
|
array( |
261
|
|
|
'name' => '', |
262
|
|
|
'declare' => false, |
263
|
|
|
) |
264
|
|
|
) |
265
|
|
|
) |
266
|
|
|
), |
267
|
|
|
$definition->getMethodCalls() |
268
|
|
|
); |
269
|
|
|
$this->assertEquals('My\Foo\Producer', $definition->getClass()); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @group alias |
274
|
|
|
*/ |
275
|
|
|
public function testAliasedFooProducerDefinition() |
276
|
|
|
{ |
277
|
|
|
$container = $this->getContainer('test.yml'); |
278
|
|
|
|
279
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
280
|
|
|
$this->assertTrue($container->has('foo_producer_alias')); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function testDefaultProducerDefinition() |
284
|
|
|
{ |
285
|
|
|
$container = $this->getContainer('test.yml'); |
286
|
|
|
|
287
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.default_producer_producer')); |
288
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_producer_producer'); |
289
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
290
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_producer'); |
291
|
|
|
$this->assertEquals(array( |
292
|
|
|
array( |
293
|
|
|
'setExchangeOptions', |
294
|
|
|
array( |
295
|
|
|
array( |
296
|
|
|
'name' => 'default_exchange', |
297
|
|
|
'type' => 'direct', |
298
|
|
|
'passive' => false, |
299
|
|
|
'durable' => true, |
300
|
|
|
'auto_delete' => false, |
301
|
|
|
'internal' => false, |
302
|
|
|
'nowait' => false, |
303
|
|
|
'arguments' => null, |
304
|
|
|
'ticket' => null, |
305
|
|
|
'declare' => true, |
306
|
|
|
) |
307
|
|
|
) |
308
|
|
|
), |
309
|
|
|
array( |
310
|
|
|
'setQueueOptions', |
311
|
|
|
array( |
312
|
|
|
array( |
313
|
|
|
'name' => '', |
314
|
|
|
'declare' => false, |
315
|
|
|
) |
316
|
|
|
) |
317
|
|
|
) |
318
|
|
|
), |
319
|
|
|
$definition->getMethodCalls() |
320
|
|
|
); |
321
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function testFooConsumerDefinition() |
325
|
|
|
{ |
326
|
|
|
$container = $this->getContainer('test.yml'); |
327
|
|
|
|
328
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
329
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
330
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
331
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
332
|
|
|
$this->assertEquals(array( |
333
|
|
|
array( |
334
|
|
|
'setExchangeOptions', |
335
|
|
|
array( |
336
|
|
|
array( |
337
|
|
|
'name' => 'foo_exchange', |
338
|
|
|
'type' => 'direct', |
339
|
|
|
'passive' => true, |
340
|
|
|
'durable' => false, |
341
|
|
|
'auto_delete' => true, |
342
|
|
|
'internal' => true, |
343
|
|
|
'nowait' => true, |
344
|
|
|
'arguments' => null, |
345
|
|
|
'ticket' => null, |
346
|
|
|
'declare' => true, |
347
|
|
|
) |
348
|
|
|
) |
349
|
|
|
), |
350
|
|
|
array( |
351
|
|
|
'setQueueOptions', |
352
|
|
|
array( |
353
|
|
|
array( |
354
|
|
|
'name' => 'foo_queue', |
355
|
|
|
'passive' => true, |
356
|
|
|
'durable' => false, |
357
|
|
|
'exclusive' => true, |
358
|
|
|
'auto_delete' => true, |
359
|
|
|
'nowait' => true, |
360
|
|
|
'arguments' => null, |
361
|
|
|
'ticket' => null, |
362
|
|
|
'routing_keys' => array('android.#.upload', 'iphone.upload'), |
363
|
|
|
'declare' => true, |
364
|
|
|
) |
365
|
|
|
) |
366
|
|
|
), |
367
|
|
|
array( |
368
|
|
|
'setCallback', |
369
|
|
|
array(array(new Reference('foo.callback'), 'execute')) |
370
|
|
|
), |
371
|
|
|
array( |
372
|
|
|
'setTimeoutWait', |
373
|
|
|
array(3) |
374
|
|
|
) |
375
|
|
|
), |
376
|
|
|
$definition->getMethodCalls() |
377
|
|
|
); |
378
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
public function testDefaultConsumerDefinition() |
382
|
|
|
{ |
383
|
|
|
$container = $this->getContainer('test.yml'); |
384
|
|
|
|
385
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
386
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
387
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
388
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
389
|
|
|
$this->assertEquals(array( |
390
|
|
|
array( |
391
|
|
|
'setExchangeOptions', |
392
|
|
|
array( |
393
|
|
|
array( |
394
|
|
|
'name' => 'default_exchange', |
395
|
|
|
'type' => 'direct', |
396
|
|
|
'passive' => false, |
397
|
|
|
'durable' => true, |
398
|
|
|
'auto_delete' => false, |
399
|
|
|
'internal' => false, |
400
|
|
|
'nowait' => false, |
401
|
|
|
'arguments' => null, |
402
|
|
|
'ticket' => null, |
403
|
|
|
'declare' => true, |
404
|
|
|
) |
405
|
|
|
) |
406
|
|
|
), |
407
|
|
|
array( |
408
|
|
|
'setQueueOptions', |
409
|
|
|
array( |
410
|
|
|
array( |
411
|
|
|
'name' => 'default_queue', |
412
|
|
|
'passive' => false, |
413
|
|
|
'durable' => true, |
414
|
|
|
'exclusive' => false, |
415
|
|
|
'auto_delete' => false, |
416
|
|
|
'nowait' => false, |
417
|
|
|
'arguments' => null, |
418
|
|
|
'ticket' => null, |
419
|
|
|
'routing_keys' => array(), |
420
|
|
|
'declare' => true, |
421
|
|
|
) |
422
|
|
|
) |
423
|
|
|
), |
424
|
|
|
array( |
425
|
|
|
'setCallback', |
426
|
|
|
array(array(new Reference('default.callback'), 'execute')) |
427
|
|
|
) |
428
|
|
|
), |
429
|
|
|
$definition->getMethodCalls() |
430
|
|
|
); |
431
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
public function testConsumerWithQosOptions() |
435
|
|
|
{ |
436
|
|
|
$container = $this->getContainer('test.yml'); |
437
|
|
|
|
438
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
439
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
440
|
|
|
$methodCalls = $definition->getMethodCalls(); |
441
|
|
|
|
442
|
|
|
$setQosParameters = null; |
443
|
|
|
foreach ($methodCalls as $methodCall) { |
444
|
|
|
if ($methodCall[0] === 'setQosOptions') { |
445
|
|
|
$setQosParameters = $methodCall[1]; |
446
|
|
|
} |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
$this->assertIsArray($setQosParameters); |
450
|
|
|
$this->assertEquals( |
451
|
|
|
array( |
452
|
|
|
1024, |
453
|
|
|
1, |
454
|
|
|
true |
455
|
|
|
), |
456
|
|
|
$setQosParameters |
457
|
|
|
); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
public function testMultipleConsumerDefinition() |
461
|
|
|
{ |
462
|
|
|
$container = $this->getContainer('test.yml'); |
463
|
|
|
|
464
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
465
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
466
|
|
|
$this->assertEquals(array( |
467
|
|
|
array( |
468
|
|
|
'setExchangeOptions', |
469
|
|
|
array( |
470
|
|
|
array( |
471
|
|
|
'name' => 'foo_multiple_exchange', |
472
|
|
|
'type' => 'direct', |
473
|
|
|
'passive' => false, |
474
|
|
|
'durable' => true, |
475
|
|
|
'auto_delete' => false, |
476
|
|
|
'internal' => false, |
477
|
|
|
'nowait' => false, |
478
|
|
|
'arguments' => null, |
479
|
|
|
'ticket' => null, |
480
|
|
|
'declare' => true, |
481
|
|
|
) |
482
|
|
|
) |
483
|
|
|
), |
484
|
|
|
array( |
485
|
|
|
'setQueues', |
486
|
|
|
array( |
487
|
|
|
array( |
488
|
|
|
'multi_test_1' => array( |
489
|
|
|
'name' => 'multi_test_1', |
490
|
|
|
'passive' => false, |
491
|
|
|
'durable' => true, |
492
|
|
|
'exclusive' => false, |
493
|
|
|
'auto_delete' => false, |
494
|
|
|
'nowait' => false, |
495
|
|
|
'arguments' => null, |
496
|
|
|
'ticket' => null, |
497
|
|
|
'routing_keys' => array(), |
498
|
|
|
'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
499
|
|
|
'declare' => true, |
500
|
|
|
), |
501
|
|
|
'foo_bar_2' => array( |
502
|
|
|
'name' => 'foo_bar_2', |
503
|
|
|
'passive' => true, |
504
|
|
|
'durable' => false, |
505
|
|
|
'exclusive' => true, |
506
|
|
|
'auto_delete' => true, |
507
|
|
|
'nowait' => true, |
508
|
|
|
'arguments' => null, |
509
|
|
|
'ticket' => null, |
510
|
|
|
'routing_keys' => array( |
511
|
|
|
'android.upload', |
512
|
|
|
'iphone.upload' |
513
|
|
|
), |
514
|
|
|
'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
515
|
|
|
'declare' => true, |
516
|
|
|
) |
517
|
|
|
) |
518
|
|
|
) |
519
|
|
|
), |
520
|
|
|
array( |
521
|
|
|
'setQueuesProvider', |
522
|
|
|
array( |
523
|
|
|
new Reference('foo.queues_provider') |
524
|
|
|
) |
525
|
|
|
), |
526
|
|
|
array( |
527
|
|
|
'setTimeoutWait', |
528
|
|
|
array(3) |
529
|
|
|
) |
530
|
|
|
), |
531
|
|
|
$definition->getMethodCalls() |
532
|
|
|
); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
public function testDynamicConsumerDefinition() |
536
|
|
|
{ |
537
|
|
|
$container = $this->getContainer('test.yml'); |
538
|
|
|
|
539
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
540
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
541
|
|
|
|
542
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
543
|
|
|
$this->assertEquals(array( |
544
|
|
|
array( |
545
|
|
|
'setExchangeOptions', |
546
|
|
|
array( |
547
|
|
|
array( |
548
|
|
|
'name' => 'foo_dynamic_exchange', |
549
|
|
|
'type' => 'direct', |
550
|
|
|
'passive' => false, |
551
|
|
|
'durable' => true, |
552
|
|
|
'auto_delete' => false, |
553
|
|
|
'internal' => false, |
554
|
|
|
'nowait' => false, |
555
|
|
|
'declare' => true, |
556
|
|
|
'arguments' => NULL, |
557
|
|
|
'ticket' => NULL, |
558
|
|
|
) |
559
|
|
|
) |
560
|
|
|
), |
561
|
|
|
array( |
562
|
|
|
'setCallback', |
563
|
|
|
array( |
564
|
|
|
array(new Reference('foo.dynamic.callback'), 'execute') |
565
|
|
|
) |
566
|
|
|
), |
567
|
|
|
array( |
568
|
|
|
'setQueueOptionsProvider', |
569
|
|
|
array( |
570
|
|
|
new Reference('foo.dynamic.provider') |
571
|
|
|
) |
572
|
|
|
) |
573
|
|
|
), |
574
|
|
|
$definition->getMethodCalls() |
575
|
|
|
); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
public function testFooAnonConsumerDefinition() |
579
|
|
|
{ |
580
|
|
|
$container = $this->getContainer('test.yml'); |
581
|
|
|
|
582
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
583
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
584
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
585
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
586
|
|
|
$this->assertEquals(array( |
587
|
|
|
array( |
588
|
|
|
'setExchangeOptions', |
589
|
|
|
array( |
590
|
|
|
array( |
591
|
|
|
'name' => 'foo_anon_exchange', |
592
|
|
|
'type' => 'direct', |
593
|
|
|
'passive' => true, |
594
|
|
|
'durable' => false, |
595
|
|
|
'auto_delete' => true, |
596
|
|
|
'internal' => true, |
597
|
|
|
'nowait' => true, |
598
|
|
|
'arguments' => null, |
599
|
|
|
'ticket' => null, |
600
|
|
|
'declare' => true, |
601
|
|
|
) |
602
|
|
|
) |
603
|
|
|
), |
604
|
|
|
array( |
605
|
|
|
'setCallback', |
606
|
|
|
array(array(new Reference('foo_anon.callback'), 'execute')) |
607
|
|
|
) |
608
|
|
|
), |
609
|
|
|
$definition->getMethodCalls() |
610
|
|
|
); |
611
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
public function testDefaultAnonConsumerDefinition() |
615
|
|
|
{ |
616
|
|
|
$container = $this->getContainer('test.yml'); |
617
|
|
|
|
618
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
619
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
620
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
621
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
622
|
|
|
$this->assertEquals(array( |
623
|
|
|
array( |
624
|
|
|
'setExchangeOptions', |
625
|
|
|
array( |
626
|
|
|
array( |
627
|
|
|
'name' => 'default_anon_exchange', |
628
|
|
|
'type' => 'direct', |
629
|
|
|
'passive' => false, |
630
|
|
|
'durable' => true, |
631
|
|
|
'auto_delete' => false, |
632
|
|
|
'internal' => false, |
633
|
|
|
'nowait' => false, |
634
|
|
|
'arguments' => null, |
635
|
|
|
'ticket' => null, |
636
|
|
|
'declare' => true, |
637
|
|
|
) |
638
|
|
|
) |
639
|
|
|
), |
640
|
|
|
array( |
641
|
|
|
'setCallback', |
642
|
|
|
array(array(new Reference('default_anon.callback'), 'execute')) |
643
|
|
|
) |
644
|
|
|
), |
645
|
|
|
$definition->getMethodCalls() |
646
|
|
|
); |
647
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
public function testFooRpcClientDefinition() |
651
|
|
|
{ |
652
|
|
|
$container = $this->getContainer('rpc-clients.yml'); |
653
|
|
|
|
654
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
655
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
656
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
657
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
658
|
|
|
$this->assertEquals( |
659
|
|
|
array( |
660
|
|
|
array('initClient', array(true)), |
661
|
|
|
array('setUnserializer', array('json_decode')), |
662
|
|
|
array('setDirectReplyTo', array(true)), |
663
|
|
|
), |
664
|
|
|
$definition->getMethodCalls() |
665
|
|
|
); |
666
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
public function testDefaultRpcClientDefinition() |
670
|
|
|
{ |
671
|
|
|
$container = $this->getContainer('rpc-clients.yml'); |
672
|
|
|
|
673
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.default_client_rpc')); |
674
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_client_rpc'); |
675
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
676
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_client'); |
677
|
|
|
$this->assertEquals( |
678
|
|
|
array( |
679
|
|
|
array('initClient', array(true)), |
680
|
|
|
array('setUnserializer', array('unserialize')), |
681
|
|
|
array('setDirectReplyTo', array(false)), |
682
|
|
|
), |
683
|
|
|
$definition->getMethodCalls() |
684
|
|
|
); |
685
|
|
|
$this->assertFalse($definition->isLazy()); |
686
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
public function testLazyRpcClientDefinition() |
690
|
|
|
{ |
691
|
|
|
$container = $this->getContainer('rpc-clients.yml'); |
692
|
|
|
|
693
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
694
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
695
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
696
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
697
|
|
|
$this->assertEquals( |
698
|
|
|
array( |
699
|
|
|
array('initClient', array(true)), |
700
|
|
|
array('setUnserializer', array('unserialize')), |
701
|
|
|
array('setDirectReplyTo', array(false)), |
702
|
|
|
), |
703
|
|
|
$definition->getMethodCalls() |
704
|
|
|
); |
705
|
|
|
$this->assertTrue($definition->isLazy()); |
706
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
public function testFooRpcServerDefinition() |
710
|
|
|
{ |
711
|
|
|
$container = $this->getContainer('test.yml'); |
712
|
|
|
|
713
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
714
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
715
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
716
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
717
|
|
|
$this->assertEquals(array( |
718
|
|
|
array('initServer', array('foo_server')), |
719
|
|
|
array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
720
|
|
|
array('setSerializer', array('json_encode')), |
721
|
|
|
), |
722
|
|
|
$definition->getMethodCalls() |
723
|
|
|
); |
724
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
public function testDefaultRpcServerDefinition() |
728
|
|
|
{ |
729
|
|
|
$container = $this->getContainer('test.yml'); |
730
|
|
|
|
731
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
732
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
733
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
734
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
735
|
|
|
$this->assertEquals(array( |
736
|
|
|
array('initServer', array('default_server')), |
737
|
|
|
array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
738
|
|
|
array('setSerializer', array('serialize')), |
739
|
|
|
), |
740
|
|
|
$definition->getMethodCalls() |
741
|
|
|
); |
742
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
public function testRpcServerWithQueueOptionsDefinition() |
746
|
|
|
{ |
747
|
|
|
$container = $this->getContainer('test.yml'); |
748
|
|
|
|
749
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
750
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server'); |
751
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
752
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options'); |
753
|
|
|
$this->assertEquals(array( |
754
|
|
|
array('initServer', array('server_with_queue_options')), |
755
|
|
|
array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
756
|
|
|
array('setQueueOptions', array(array( |
757
|
|
|
'name' => 'server_with_queue_options-queue', |
758
|
|
|
'passive' => false, |
759
|
|
|
'durable' => true, |
760
|
|
|
'exclusive' => false, |
761
|
|
|
'auto_delete' => false, |
762
|
|
|
'nowait' => false, |
763
|
|
|
'arguments' => null, |
764
|
|
|
'ticket' => null, |
765
|
|
|
'routing_keys' => array(), |
766
|
|
|
'declare' => true, |
767
|
|
|
))), |
768
|
|
|
array('setSerializer', array('serialize')), |
769
|
|
|
), |
770
|
|
|
$definition->getMethodCalls() |
771
|
|
|
); |
772
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
public function testRpcServerWithExchangeOptionsDefinition() |
776
|
|
|
{ |
777
|
|
|
$container = $this->getContainer('test.yml'); |
778
|
|
|
|
779
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
780
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
781
|
|
|
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
782
|
|
|
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
783
|
|
|
$this->assertEquals(array( |
784
|
|
|
array('initServer', array('server_with_exchange_options')), |
785
|
|
|
array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
786
|
|
|
array('setExchangeOptions', array(array( |
787
|
|
|
'name' => 'exchange', |
788
|
|
|
'type' => 'topic', |
789
|
|
|
'passive' => false, |
790
|
|
|
'durable' => true, |
791
|
|
|
'auto_delete' => false, |
792
|
|
|
'internal' => null, |
793
|
|
|
'nowait' => false, |
794
|
|
|
'declare' => true, |
795
|
|
|
'arguments' => null, |
796
|
|
|
'ticket' => null, |
797
|
|
|
))), |
798
|
|
|
array('setSerializer', array('serialize')), |
799
|
|
|
), |
800
|
|
|
$definition->getMethodCalls() |
801
|
|
|
); |
802
|
|
|
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
803
|
|
|
} |
804
|
|
|
|
805
|
|
|
public function testHasCollectorWhenChannelsExist() |
806
|
|
|
{ |
807
|
|
|
$container = $this->getContainer('collector.yml'); |
808
|
|
|
|
809
|
|
|
$this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
810
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
811
|
|
|
|
812
|
|
|
$this->assertEquals(array( |
813
|
|
|
new Reference('old_sound_rabbit_mq.channel.default_producer'), |
814
|
|
|
new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
815
|
|
|
), |
816
|
|
|
$definition->getArgument(0) |
817
|
|
|
); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
public function testHasNoCollectorWhenNoChannelsExist() |
821
|
|
|
{ |
822
|
|
|
$container = $this->getContainer('no_collector.yml'); |
823
|
|
|
$this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
public function testCollectorCanBeDisabled() |
827
|
|
|
{ |
828
|
|
|
$container = $this->getContainer('collector_disabled.yml'); |
829
|
|
|
$this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
public function testExchangeArgumentsAreArray() |
833
|
|
|
{ |
834
|
|
|
$container = $this->getContainer('exchange_arguments.yml'); |
835
|
|
|
|
836
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
837
|
|
|
$calls = $definition->getMethodCalls(); |
838
|
|
|
$this->assertEquals('setExchangeOptions', $calls[0][0]); |
839
|
|
|
$options = $calls[0][1]; |
840
|
|
|
$this->assertEquals(array('name' => 'bar'), $options[0]['arguments']); |
841
|
|
|
|
842
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.consumer_consumer'); |
843
|
|
|
$calls = $definition->getMethodCalls(); |
844
|
|
|
$this->assertEquals('setExchangeOptions', $calls[0][0]); |
845
|
|
|
$options = $calls[0][1]; |
846
|
|
|
$this->assertEquals(array('name' => 'bar'), $options[0]['arguments']); |
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
850
|
|
|
{ |
851
|
|
|
$container = $this->getContainer('no_exchange_options.yml'); |
852
|
|
|
|
853
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
854
|
|
|
$calls = $definition->getMethodCalls(); |
855
|
|
|
$this->assertEquals('setExchangeOptions', $calls[0][0]); |
856
|
|
|
$options = $calls[0][1]; |
857
|
|
|
|
858
|
|
|
$this->assertEquals('', $options[0]['name']); |
859
|
|
|
$this->assertEquals('direct', $options[0]['type']); |
860
|
|
|
$this->assertEquals(false, $options[0]['declare']); |
861
|
|
|
$this->assertEquals(true, $options[0]['passive']); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
public function testProducersWithLogger() |
865
|
|
|
{ |
866
|
|
|
$container = $this->getContainer('config_with_enable_logger.yml'); |
867
|
|
|
$definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
868
|
|
|
$this->assertTrue( |
869
|
|
|
$definition->hasTag('monolog.logger'), 'service should be marked for logger' |
870
|
|
|
); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
private function getContainer($file, $debug = false) |
874
|
|
|
{ |
875
|
|
|
$container = new ContainerBuilder(new ParameterBag(array('kernel.debug' => $debug))); |
876
|
|
|
$container->registerExtension(new OldSoundRabbitMqExtension()); |
877
|
|
|
|
878
|
|
|
$locator = new FileLocator(__DIR__.'/Fixtures'); |
879
|
|
|
$loader = new YamlFileLoader($container, $locator); |
880
|
|
|
$loader->load($file); |
881
|
|
|
|
882
|
|
|
$container->getCompilerPassConfig()->setOptimizationPasses(array()); |
883
|
|
|
$container->getCompilerPassConfig()->setRemovingPasses(array()); |
884
|
|
|
$container->compile(); |
885
|
|
|
|
886
|
|
|
return $container; |
887
|
|
|
} |
888
|
|
|
} |
889
|
|
|
|