Total Complexity | 42 |
Total Lines | 978 |
Duplicated Lines | 0 % |
Changes | 20 | ||
Bugs | 1 | Features | 1 |
Complex classes like OldSoundRabbitMqExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OldSoundRabbitMqExtensionTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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 | 'hosts' => [], |
||
40 | ), $factory->getArgument(1)); |
||
41 | $this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
||
42 | } |
||
43 | |||
44 | public function testSslConnectionDefinition() |
||
45 | { |
||
46 | $container = $this->getContainer('test.yml'); |
||
47 | |||
48 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.ssl_connection')); |
||
49 | $definition = $container->getDefinition('old_sound_rabbit_mq.connection.ssl_connection'); |
||
50 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.ssl_connection')); |
||
51 | $factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.ssl_connection'); |
||
52 | $this->assertEquals(array('old_sound_rabbit_mq.connection_factory.ssl_connection', 'createConnection'), $definition->getFactory()); |
||
53 | $this->assertEquals(array( |
||
54 | 'host' => 'ssl_host', |
||
55 | 'port' => 123, |
||
56 | 'user' => 'ssl_user', |
||
57 | 'password' => 'ssl_password', |
||
58 | 'vhost' => '/ssl', |
||
59 | 'lazy' => false, |
||
60 | 'connection_timeout' => 3, |
||
61 | 'read_write_timeout' => 3, |
||
62 | 'ssl_context' => array( |
||
63 | 'verify_peer' => false, |
||
64 | ), |
||
65 | 'keepalive' => false, |
||
66 | 'heartbeat' => 0, |
||
67 | 'use_socket' => false, |
||
68 | 'url' => '', |
||
69 | 'hosts' => [], |
||
70 | ), $factory->getArgument(1)); |
||
71 | $this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
||
72 | } |
||
73 | |||
74 | public function testLazyConnectionDefinition() |
||
75 | { |
||
76 | $container = $this->getContainer('test.yml'); |
||
77 | |||
78 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_connection')); |
||
79 | $definition = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_connection'); |
||
80 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_connection')); |
||
81 | $factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.lazy_connection'); |
||
82 | $this->assertEquals(array('old_sound_rabbit_mq.connection_factory.lazy_connection', 'createConnection'), $definition->getFactory()); |
||
83 | $this->assertEquals(array( |
||
84 | 'host' => 'lazy_host', |
||
85 | 'port' => 456, |
||
86 | 'user' => 'lazy_user', |
||
87 | 'password' => 'lazy_password', |
||
88 | 'vhost' => '/lazy', |
||
89 | 'lazy' => true, |
||
90 | 'connection_timeout' => 3, |
||
91 | 'read_write_timeout' => 3, |
||
92 | 'ssl_context' => array(), |
||
93 | 'keepalive' => false, |
||
94 | 'heartbeat' => 0, |
||
95 | 'use_socket' => false, |
||
96 | 'url' => '', |
||
97 | 'hosts' => [], |
||
98 | ), $factory->getArgument(1)); |
||
99 | $this->assertEquals('%old_sound_rabbit_mq.lazy.connection.class%', $definition->getClass()); |
||
100 | } |
||
101 | |||
102 | public function testDefaultConnectionDefinition() |
||
103 | { |
||
104 | $container = $this->getContainer('test.yml'); |
||
105 | |||
106 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.default')); |
||
107 | $definition = $container->getDefinition('old_sound_rabbit_mq.connection.default'); |
||
108 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.default')); |
||
109 | $factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.default'); |
||
110 | $this->assertEquals(array('old_sound_rabbit_mq.connection_factory.default', 'createConnection'), $definition->getFactory()); |
||
111 | $this->assertEquals(array( |
||
112 | 'host' => 'localhost', |
||
113 | 'port' => 5672, |
||
114 | 'user' => 'guest', |
||
115 | 'password' => 'guest', |
||
116 | 'vhost' => '/', |
||
117 | 'lazy' => false, |
||
118 | 'connection_timeout' => 3, |
||
119 | 'read_write_timeout' => 3, |
||
120 | 'ssl_context' => array(), |
||
121 | 'keepalive' => false, |
||
122 | 'heartbeat' => 0, |
||
123 | 'use_socket' => false, |
||
124 | 'url' => '', |
||
125 | 'hosts' => [], |
||
126 | ), $factory->getArgument(1)); |
||
127 | $this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
||
128 | } |
||
129 | |||
130 | public function testSocketConnectionDefinition() |
||
131 | { |
||
132 | $container = $this->getContainer('test.yml'); |
||
133 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.socket_connection')); |
||
134 | $definiton = $container->getDefinition('old_sound_rabbit_mq.connection.socket_connection'); |
||
135 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.socket_connection')); |
||
136 | $this->assertEquals('%old_sound_rabbit_mq.socket_connection.class%', $definiton->getClass()); |
||
137 | } |
||
138 | |||
139 | public function testLazySocketConnectionDefinition() |
||
146 | } |
||
147 | |||
148 | public function testClusterConnectionDefinition() |
||
149 | { |
||
150 | $container = $this->getContainer('test.yml'); |
||
151 | |||
152 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.cluster_connection')); |
||
153 | $definition = $container->getDefinition('old_sound_rabbit_mq.connection.cluster_connection'); |
||
154 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.cluster_connection')); |
||
155 | $factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.cluster_connection'); |
||
156 | $this->assertEquals(['old_sound_rabbit_mq.connection_factory.cluster_connection', 'createConnection'], $definition->getFactory()); |
||
157 | $this->assertEquals([ |
||
158 | 'hosts' => [ |
||
159 | [ |
||
160 | 'host' => 'cluster_host', |
||
161 | 'port' => 111, |
||
162 | 'user' => 'cluster_user', |
||
163 | 'password' => 'cluster_password', |
||
164 | 'vhost' => '/cluster', |
||
165 | 'url' => '' |
||
166 | ], |
||
167 | [ |
||
168 | 'host' => 'localhost', |
||
169 | 'port' => 5672, |
||
170 | 'user' => 'guest', |
||
171 | 'password' => 'guest', |
||
172 | 'vhost' => '/', |
||
173 | 'url' => 'amqp://cluster_url_host:cluster_url_pass@host:10000/cluster_url_vhost' |
||
174 | ] |
||
175 | ], |
||
176 | 'host' => 'localhost', |
||
177 | 'port' => 5672, |
||
178 | 'user' => 'guest', |
||
179 | 'password' => 'guest', |
||
180 | 'vhost' => '/', |
||
181 | 'lazy' => false, |
||
182 | 'connection_timeout' => 3, |
||
183 | 'read_write_timeout' => 3, |
||
184 | 'ssl_context' => array(), |
||
185 | 'keepalive' => false, |
||
186 | 'heartbeat' => 0, |
||
187 | 'use_socket' => false, |
||
188 | 'url' => '', |
||
189 | ], $factory->getArgument(1)); |
||
190 | $this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
||
191 | } |
||
192 | |||
193 | public function testFooBinding() |
||
194 | { |
||
195 | $container = $this->getContainer('test.yml'); |
||
196 | $binding = array( |
||
197 | 'arguments' => null, |
||
198 | 'class' => '%old_sound_rabbit_mq.binding.class%', |
||
199 | 'connection' => 'default', |
||
200 | 'exchange' => 'foo', |
||
201 | 'destination' => 'bar', |
||
202 | 'destination_is_exchange' => false, |
||
203 | 'nowait' => false, |
||
204 | 'routing_key' => 'baz', |
||
205 | ); |
||
206 | ksort($binding); |
||
207 | $key = md5(json_encode($binding)); |
||
208 | $name = sprintf('old_sound_rabbit_mq.binding.%s', $key); |
||
209 | $this->assertTrue($container->has($name)); |
||
210 | $definition = $container->getDefinition($name); |
||
211 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
212 | $this->assertBindingMethodCalls($definition, $binding); |
||
213 | } |
||
214 | |||
215 | public function testMooBinding() |
||
216 | { |
||
217 | $container = $this->getContainer('test.yml'); |
||
218 | $binding = array( |
||
219 | 'arguments' => array('moo' => 'cow'), |
||
220 | 'class' => '%old_sound_rabbit_mq.binding.class%', |
||
221 | 'connection' => 'default2', |
||
222 | 'exchange' => 'moo', |
||
223 | 'destination' => 'cow', |
||
224 | 'destination_is_exchange' => true, |
||
225 | 'nowait' => true, |
||
226 | 'routing_key' => null, |
||
227 | ); |
||
228 | ksort($binding); |
||
229 | $key = md5(json_encode($binding)); |
||
230 | $name = sprintf('old_sound_rabbit_mq.binding.%s', $key); |
||
231 | $this->assertTrue($container->has($name)); |
||
232 | $definition = $container->getDefinition($name); |
||
233 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default2'); |
||
234 | $this->assertBindingMethodCalls($definition, $binding); |
||
235 | } |
||
236 | |||
237 | protected function assertBindingMethodCalls(Definition $definition, $binding) |
||
278 | ); |
||
279 | } |
||
280 | public function testFooProducerDefinition() |
||
281 | { |
||
282 | $container = $this->getContainer('test.yml'); |
||
319 | } |
||
320 | |||
321 | public function testProducerArgumentAliases() |
||
322 | { |
||
323 | $container = $this->getContainer('test.yml'); |
||
324 | |||
325 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
326 | // don't test if autowiring arguments functionality is not available |
||
327 | return; |
||
328 | } |
||
329 | |||
330 | // test expected aliases |
||
331 | $producerInterface = 'OldSound\RabbitMqBundle\RabbitMq\ProducerInterface'; |
||
332 | $expectedAliases = array( |
||
333 | $producerInterface . ' $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
334 | 'My\Foo\Producer $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
335 | $producerInterface . ' $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
336 | 'My\Foo\Producer $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
337 | $producerInterface . ' $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
338 | '%old_sound_rabbit_mq.producer.class% $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
339 | ); |
||
340 | |||
341 | foreach($expectedAliases as $id => $target) { |
||
342 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
343 | |||
344 | $alias = $container->getAlias($id); |
||
345 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
346 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
347 | } |
||
348 | } |
||
349 | |||
350 | /** |
||
351 | * @group alias |
||
352 | */ |
||
353 | public function testAliasedFooProducerDefinition() |
||
354 | { |
||
355 | $container = $this->getContainer('test.yml'); |
||
356 | |||
357 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
||
358 | $this->assertTrue($container->has('foo_producer_alias')); |
||
359 | } |
||
360 | |||
361 | public function testDefaultProducerDefinition() |
||
362 | { |
||
363 | $container = $this->getContainer('test.yml'); |
||
364 | |||
365 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_producer_producer')); |
||
366 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_producer_producer'); |
||
367 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
368 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_producer'); |
||
369 | $this->assertEquals(array( |
||
370 | array( |
||
371 | 'setExchangeOptions', |
||
372 | array( |
||
373 | array( |
||
374 | 'name' => 'default_exchange', |
||
375 | 'type' => 'direct', |
||
376 | 'passive' => false, |
||
377 | 'durable' => true, |
||
378 | 'auto_delete' => false, |
||
379 | 'internal' => false, |
||
380 | 'nowait' => false, |
||
381 | 'arguments' => null, |
||
382 | 'ticket' => null, |
||
383 | 'declare' => true, |
||
384 | ) |
||
385 | ) |
||
386 | ), |
||
387 | array( |
||
388 | 'setQueueOptions', |
||
389 | array( |
||
390 | array( |
||
391 | 'name' => '', |
||
392 | 'declare' => false, |
||
393 | ) |
||
394 | ) |
||
395 | ) |
||
396 | ), |
||
397 | $definition->getMethodCalls() |
||
398 | ); |
||
399 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
400 | } |
||
401 | |||
402 | public function testFooConsumerDefinition() |
||
403 | { |
||
404 | $container = $this->getContainer('test.yml'); |
||
405 | |||
406 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
||
407 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
||
408 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
409 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
||
410 | $this->assertEquals(array( |
||
411 | array( |
||
412 | 'setExchangeOptions', |
||
413 | array( |
||
414 | array( |
||
415 | 'name' => 'foo_exchange', |
||
416 | 'type' => 'direct', |
||
417 | 'passive' => true, |
||
418 | 'durable' => false, |
||
419 | 'auto_delete' => true, |
||
420 | 'internal' => true, |
||
421 | 'nowait' => true, |
||
422 | 'arguments' => null, |
||
423 | 'ticket' => null, |
||
424 | 'declare' => true, |
||
425 | ) |
||
426 | ) |
||
427 | ), |
||
428 | array( |
||
429 | 'setQueueOptions', |
||
430 | array( |
||
431 | array( |
||
432 | 'name' => 'foo_queue', |
||
433 | 'passive' => true, |
||
434 | 'durable' => false, |
||
435 | 'exclusive' => true, |
||
436 | 'auto_delete' => true, |
||
437 | 'nowait' => true, |
||
438 | 'arguments' => null, |
||
439 | 'ticket' => null, |
||
440 | 'routing_keys' => array('android.#.upload', 'iphone.upload'), |
||
441 | 'declare' => true, |
||
442 | ) |
||
443 | ) |
||
444 | ), |
||
445 | array( |
||
446 | 'setCallback', |
||
447 | array(array(new Reference('foo.callback'), 'execute')) |
||
448 | ), |
||
449 | array( |
||
450 | 'setTimeoutWait', |
||
451 | array(3) |
||
452 | ) |
||
453 | ), |
||
454 | $definition->getMethodCalls() |
||
455 | ); |
||
456 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
457 | } |
||
458 | |||
459 | public function testConsumerArgumentAliases() |
||
460 | { |
||
461 | $container = $this->getContainer('test.yml'); |
||
462 | |||
463 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
464 | // don't test if autowiring arguments functionality is not available |
||
465 | return; |
||
466 | } |
||
467 | |||
468 | $consumerInterface = 'OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface'; |
||
469 | $expectedAliases = array( |
||
470 | $consumerInterface . ' $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
471 | '%old_sound_rabbit_mq.consumer.class% $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
472 | $consumerInterface . ' $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
473 | '%old_sound_rabbit_mq.consumer.class% $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
474 | $consumerInterface . ' $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer', |
||
475 | '%old_sound_rabbit_mq.consumer.class% $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer' |
||
476 | ); |
||
477 | foreach($expectedAliases as $id => $target) { |
||
478 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
479 | |||
480 | $alias = $container->getAlias($id); |
||
481 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
482 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
483 | } |
||
484 | } |
||
485 | |||
486 | public function testDefaultConsumerDefinition() |
||
487 | { |
||
488 | $container = $this->getContainer('test.yml'); |
||
489 | |||
490 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
||
491 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
492 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
493 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
||
494 | $this->assertEquals(array( |
||
495 | array( |
||
496 | 'setExchangeOptions', |
||
497 | array( |
||
498 | array( |
||
499 | 'name' => 'default_exchange', |
||
500 | 'type' => 'direct', |
||
501 | 'passive' => false, |
||
502 | 'durable' => true, |
||
503 | 'auto_delete' => false, |
||
504 | 'internal' => false, |
||
505 | 'nowait' => false, |
||
506 | 'arguments' => null, |
||
507 | 'ticket' => null, |
||
508 | 'declare' => true, |
||
509 | ) |
||
510 | ) |
||
511 | ), |
||
512 | array( |
||
513 | 'setQueueOptions', |
||
514 | array( |
||
515 | array( |
||
516 | 'name' => 'default_queue', |
||
517 | 'passive' => false, |
||
518 | 'durable' => true, |
||
519 | 'exclusive' => false, |
||
520 | 'auto_delete' => false, |
||
521 | 'nowait' => false, |
||
522 | 'arguments' => null, |
||
523 | 'ticket' => null, |
||
524 | 'routing_keys' => array(), |
||
525 | 'declare' => true, |
||
526 | ) |
||
527 | ) |
||
528 | ), |
||
529 | array( |
||
530 | 'setCallback', |
||
531 | array(array(new Reference('default.callback'), 'execute')) |
||
532 | ) |
||
533 | ), |
||
534 | $definition->getMethodCalls() |
||
535 | ); |
||
536 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
537 | } |
||
538 | |||
539 | public function testConsumerWithQosOptions() |
||
540 | { |
||
541 | $container = $this->getContainer('test.yml'); |
||
542 | |||
543 | $this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
||
544 | $definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
||
545 | $methodCalls = $definition->getMethodCalls(); |
||
546 | |||
547 | $setQosParameters = null; |
||
548 | foreach ($methodCalls as $methodCall) { |
||
549 | if ($methodCall[0] === 'setQosOptions') { |
||
550 | $setQosParameters = $methodCall[1]; |
||
551 | } |
||
552 | } |
||
553 | |||
554 | $this->assertIsArray($setQosParameters); |
||
555 | $this->assertEquals( |
||
556 | array( |
||
557 | 1024, |
||
558 | 1, |
||
559 | true |
||
560 | ), |
||
561 | $setQosParameters |
||
562 | ); |
||
563 | } |
||
564 | |||
565 | public function testMultipleConsumerDefinition() |
||
566 | { |
||
567 | $container = $this->getContainer('test.yml'); |
||
568 | |||
569 | $this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
||
570 | $definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
||
571 | $this->assertEquals(array( |
||
572 | array( |
||
573 | 'setExchangeOptions', |
||
574 | array( |
||
575 | array( |
||
576 | 'name' => 'foo_multiple_exchange', |
||
577 | 'type' => 'direct', |
||
578 | 'passive' => false, |
||
579 | 'durable' => true, |
||
580 | 'auto_delete' => false, |
||
581 | 'internal' => false, |
||
582 | 'nowait' => false, |
||
583 | 'arguments' => null, |
||
584 | 'ticket' => null, |
||
585 | 'declare' => true, |
||
586 | ) |
||
587 | ) |
||
588 | ), |
||
589 | array( |
||
590 | 'setQueues', |
||
591 | array( |
||
592 | array( |
||
593 | 'multi_test_1' => array( |
||
594 | 'name' => 'multi_test_1', |
||
595 | 'passive' => false, |
||
596 | 'durable' => true, |
||
597 | 'exclusive' => false, |
||
598 | 'auto_delete' => false, |
||
599 | 'nowait' => false, |
||
600 | 'arguments' => null, |
||
601 | 'ticket' => null, |
||
602 | 'routing_keys' => array(), |
||
603 | 'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
||
604 | 'declare' => true, |
||
605 | ), |
||
606 | 'foo_bar_2' => array( |
||
607 | 'name' => 'foo_bar_2', |
||
608 | 'passive' => true, |
||
609 | 'durable' => false, |
||
610 | 'exclusive' => true, |
||
611 | 'auto_delete' => true, |
||
612 | 'nowait' => true, |
||
613 | 'arguments' => null, |
||
614 | 'ticket' => null, |
||
615 | 'routing_keys' => array( |
||
616 | 'android.upload', |
||
617 | 'iphone.upload' |
||
618 | ), |
||
619 | 'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
||
620 | 'declare' => true, |
||
621 | ) |
||
622 | ) |
||
623 | ) |
||
624 | ), |
||
625 | array( |
||
626 | 'setQueuesProvider', |
||
627 | array( |
||
628 | new Reference('foo.queues_provider') |
||
629 | ) |
||
630 | ), |
||
631 | array( |
||
632 | 'setTimeoutWait', |
||
633 | array(3) |
||
634 | ) |
||
635 | ), |
||
636 | $definition->getMethodCalls() |
||
637 | ); |
||
638 | } |
||
639 | |||
640 | public function testDynamicConsumerDefinition() |
||
641 | { |
||
642 | $container = $this->getContainer('test.yml'); |
||
643 | |||
644 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
||
645 | $this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
||
646 | |||
647 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
||
648 | $this->assertEquals(array( |
||
649 | array( |
||
650 | 'setExchangeOptions', |
||
651 | array( |
||
652 | array( |
||
653 | 'name' => 'foo_dynamic_exchange', |
||
654 | 'type' => 'direct', |
||
655 | 'passive' => false, |
||
656 | 'durable' => true, |
||
657 | 'auto_delete' => false, |
||
658 | 'internal' => false, |
||
659 | 'nowait' => false, |
||
660 | 'declare' => true, |
||
661 | 'arguments' => NULL, |
||
662 | 'ticket' => NULL, |
||
663 | ) |
||
664 | ) |
||
665 | ), |
||
666 | array( |
||
667 | 'setCallback', |
||
668 | array( |
||
669 | array(new Reference('foo.dynamic.callback'), 'execute') |
||
670 | ) |
||
671 | ), |
||
672 | array( |
||
673 | 'setQueueOptionsProvider', |
||
674 | array( |
||
675 | new Reference('foo.dynamic.provider') |
||
676 | ) |
||
677 | ) |
||
678 | ), |
||
679 | $definition->getMethodCalls() |
||
680 | ); |
||
681 | } |
||
682 | |||
683 | public function testFooAnonConsumerDefinition() |
||
684 | { |
||
685 | $container = $this->getContainer('test.yml'); |
||
686 | |||
687 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
||
688 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
||
689 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
690 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
||
691 | $this->assertEquals(array( |
||
692 | array( |
||
693 | 'setExchangeOptions', |
||
694 | array( |
||
695 | array( |
||
696 | 'name' => 'foo_anon_exchange', |
||
697 | 'type' => 'direct', |
||
698 | 'passive' => true, |
||
699 | 'durable' => false, |
||
700 | 'auto_delete' => true, |
||
701 | 'internal' => true, |
||
702 | 'nowait' => true, |
||
703 | 'arguments' => null, |
||
704 | 'ticket' => null, |
||
705 | 'declare' => true, |
||
706 | ) |
||
707 | ) |
||
708 | ), |
||
709 | array( |
||
710 | 'setCallback', |
||
711 | array(array(new Reference('foo_anon.callback'), 'execute')) |
||
712 | ) |
||
713 | ), |
||
714 | $definition->getMethodCalls() |
||
715 | ); |
||
716 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
717 | } |
||
718 | |||
719 | public function testDefaultAnonConsumerDefinition() |
||
720 | { |
||
721 | $container = $this->getContainer('test.yml'); |
||
722 | |||
723 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
||
724 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
||
725 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
726 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
||
727 | $this->assertEquals(array( |
||
728 | array( |
||
729 | 'setExchangeOptions', |
||
730 | array( |
||
731 | array( |
||
732 | 'name' => 'default_anon_exchange', |
||
733 | 'type' => 'direct', |
||
734 | 'passive' => false, |
||
735 | 'durable' => true, |
||
736 | 'auto_delete' => false, |
||
737 | 'internal' => false, |
||
738 | 'nowait' => false, |
||
739 | 'arguments' => null, |
||
740 | 'ticket' => null, |
||
741 | 'declare' => true, |
||
742 | ) |
||
743 | ) |
||
744 | ), |
||
745 | array( |
||
746 | 'setCallback', |
||
747 | array(array(new Reference('default_anon.callback'), 'execute')) |
||
748 | ) |
||
749 | ), |
||
750 | $definition->getMethodCalls() |
||
751 | ); |
||
752 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
753 | } |
||
754 | |||
755 | public function testFooRpcClientDefinition() |
||
756 | { |
||
757 | $container = $this->getContainer('rpc-clients.yml'); |
||
758 | |||
759 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
||
760 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
||
761 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
762 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
||
763 | $this->assertEquals( |
||
764 | array( |
||
765 | array('initClient', array(true)), |
||
766 | array('setUnserializer', array('json_decode')), |
||
767 | array('setDirectReplyTo', array(true)), |
||
768 | ), |
||
769 | $definition->getMethodCalls() |
||
770 | ); |
||
771 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
772 | } |
||
773 | |||
774 | public function testDefaultRpcClientDefinition() |
||
792 | } |
||
793 | |||
794 | public function testLazyRpcClientDefinition() |
||
795 | { |
||
796 | $container = $this->getContainer('rpc-clients.yml'); |
||
797 | |||
798 | $this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
||
799 | $definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
||
800 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
801 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
||
802 | $this->assertEquals( |
||
803 | array( |
||
804 | array('initClient', array(true)), |
||
805 | array('setUnserializer', array('unserialize')), |
||
806 | array('setDirectReplyTo', array(false)), |
||
807 | ), |
||
808 | $definition->getMethodCalls() |
||
809 | ); |
||
810 | $this->assertTrue($definition->isLazy()); |
||
811 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
812 | } |
||
813 | |||
814 | public function testFooRpcServerDefinition() |
||
815 | { |
||
816 | $container = $this->getContainer('test.yml'); |
||
817 | |||
818 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
||
819 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
||
820 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
821 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
||
822 | $this->assertEquals(array( |
||
823 | array('initServer', array('foo_server')), |
||
824 | array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
||
825 | array('setSerializer', array('json_encode')), |
||
826 | ), |
||
827 | $definition->getMethodCalls() |
||
828 | ); |
||
829 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
830 | } |
||
831 | |||
832 | public function testDefaultRpcServerDefinition() |
||
833 | { |
||
834 | $container = $this->getContainer('test.yml'); |
||
835 | |||
836 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
||
837 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
||
838 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
839 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
||
840 | $this->assertEquals(array( |
||
841 | array('initServer', array('default_server')), |
||
842 | array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
||
843 | array('setSerializer', array('serialize')), |
||
844 | ), |
||
845 | $definition->getMethodCalls() |
||
846 | ); |
||
847 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
848 | } |
||
849 | |||
850 | public function testRpcServerWithQueueOptionsDefinition() |
||
851 | { |
||
852 | $container = $this->getContainer('test.yml'); |
||
853 | |||
854 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
||
855 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server'); |
||
856 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
857 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options'); |
||
858 | $this->assertEquals(array( |
||
859 | array('initServer', array('server_with_queue_options')), |
||
860 | array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
||
861 | array('setQueueOptions', array(array( |
||
862 | 'name' => 'server_with_queue_options-queue', |
||
863 | 'passive' => false, |
||
864 | 'durable' => true, |
||
865 | 'exclusive' => false, |
||
866 | 'auto_delete' => false, |
||
867 | 'nowait' => false, |
||
868 | 'arguments' => null, |
||
869 | 'ticket' => null, |
||
870 | 'routing_keys' => array(), |
||
871 | 'declare' => true, |
||
872 | ))), |
||
873 | array('setSerializer', array('serialize')), |
||
874 | ), |
||
875 | $definition->getMethodCalls() |
||
876 | ); |
||
877 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
878 | } |
||
879 | |||
880 | public function testRpcServerWithExchangeOptionsDefinition() |
||
881 | { |
||
882 | $container = $this->getContainer('test.yml'); |
||
883 | |||
884 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
||
885 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
||
886 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
887 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
||
888 | $this->assertEquals(array( |
||
889 | array('initServer', array('server_with_exchange_options')), |
||
890 | array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
||
891 | array('setExchangeOptions', array(array( |
||
892 | 'name' => 'exchange', |
||
893 | 'type' => 'topic', |
||
894 | 'passive' => false, |
||
895 | 'durable' => true, |
||
896 | 'auto_delete' => false, |
||
897 | 'internal' => null, |
||
898 | 'nowait' => false, |
||
899 | 'declare' => true, |
||
900 | 'arguments' => null, |
||
901 | 'ticket' => null, |
||
902 | ))), |
||
903 | array('setSerializer', array('serialize')), |
||
904 | ), |
||
905 | $definition->getMethodCalls() |
||
906 | ); |
||
907 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
908 | } |
||
909 | |||
910 | public function testHasCollectorWhenChannelsExist() |
||
911 | { |
||
912 | $container = $this->getContainer('collector.yml'); |
||
913 | |||
914 | $this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
||
915 | $definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
||
916 | |||
917 | $this->assertEquals(array( |
||
918 | new Reference('old_sound_rabbit_mq.channel.default_producer'), |
||
919 | new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
||
920 | ), |
||
921 | $definition->getArgument(0) |
||
922 | ); |
||
923 | } |
||
924 | |||
925 | public function testHasNoCollectorWhenNoChannelsExist() |
||
926 | { |
||
927 | $container = $this->getContainer('no_collector.yml'); |
||
928 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
929 | } |
||
930 | |||
931 | public function testCollectorCanBeDisabled() |
||
932 | { |
||
933 | $container = $this->getContainer('collector_disabled.yml'); |
||
934 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
935 | } |
||
936 | |||
937 | public function testExchangeArgumentsAreArray() |
||
952 | } |
||
953 | |||
954 | public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
||
955 | { |
||
956 | $container = $this->getContainer('no_exchange_options.yml'); |
||
957 | |||
958 | $definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
||
959 | $calls = $definition->getMethodCalls(); |
||
960 | $this->assertEquals('setExchangeOptions', $calls[0][0]); |
||
961 | $options = $calls[0][1]; |
||
962 | |||
963 | $this->assertEquals('', $options[0]['name']); |
||
964 | $this->assertEquals('direct', $options[0]['type']); |
||
965 | $this->assertEquals(false, $options[0]['declare']); |
||
966 | $this->assertEquals(true, $options[0]['passive']); |
||
967 | } |
||
968 | |||
969 | public function testProducersWithLogger() |
||
970 | { |
||
971 | $container = $this->getContainer('config_with_enable_logger.yml'); |
||
972 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
973 | $this->assertTrue( |
||
974 | $definition->hasTag('monolog.logger'), 'service should be marked for logger' |
||
975 | ); |
||
976 | } |
||
977 | |||
978 | private function getContainer($file, $debug = false) |
||
992 | } |
||
993 | } |
||
994 |