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