Total Complexity | 43 |
Total Lines | 1074 |
Duplicated Lines | 0 % |
Changes | 21 | ||
Bugs | 1 | Features | 0 |
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 |
||
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() |
||
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) |
||
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 | array( |
||
328 | 'setContentType', |
||
329 | array('text/plain') |
||
330 | ), |
||
331 | array( |
||
332 | 'setDeliveryMode', |
||
333 | array(2) |
||
334 | ) |
||
335 | |||
336 | ), |
||
337 | $definition->getMethodCalls() |
||
338 | ); |
||
339 | $this->assertEquals('My\Foo\Producer', $definition->getClass()); |
||
340 | } |
||
341 | |||
342 | public function testProducerArgumentAliases() |
||
368 | } |
||
369 | } |
||
370 | |||
371 | /** |
||
372 | * @group alias |
||
373 | */ |
||
374 | public function testAliasedFooProducerDefinition() |
||
375 | { |
||
376 | $container = $this->getContainer('test.yml'); |
||
377 | |||
378 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
||
379 | $this->assertTrue($container->has('foo_producer_alias')); |
||
380 | } |
||
381 | |||
382 | public function testDefaultProducerDefinition() |
||
439 | } |
||
440 | |||
441 | public function testConfirmatioProducerDefinition() |
||
442 | { |
||
443 | $container = $this->getContainer('test.yml'); |
||
444 | |||
445 | $this->assertTrue($container->has('old_sound_rabbit_mq.confirmation_producer_producer')); |
||
446 | $definition = $container->getDefinition('old_sound_rabbit_mq.confirmation_producer_producer'); |
||
447 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
448 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.confirmation_producer'); |
||
449 | $this->assertEquals(array( |
||
450 | array( |
||
451 | 'setExchangeOptions', |
||
452 | array( |
||
453 | array( |
||
454 | 'name' => 'default_exchange', |
||
455 | 'type' => 'direct', |
||
456 | 'passive' => false, |
||
457 | 'durable' => true, |
||
458 | 'auto_delete' => false, |
||
459 | 'internal' => false, |
||
460 | 'nowait' => false, |
||
461 | 'arguments' => null, |
||
462 | 'ticket' => null, |
||
463 | 'declare' => true, |
||
464 | ) |
||
465 | ) |
||
466 | ), |
||
467 | array( |
||
468 | 'setQueueOptions', |
||
469 | array( |
||
470 | array( |
||
471 | 'name' => '', |
||
472 | 'declare' => false, |
||
473 | ) |
||
474 | ) |
||
475 | ), |
||
476 | array( |
||
477 | 'setConfirmationTimeout', |
||
478 | array( |
||
479 | 2 |
||
480 | ) |
||
481 | ), |
||
482 | array( |
||
483 | 'setDefaultRoutingKey', |
||
484 | array('') |
||
485 | ), |
||
486 | array( |
||
487 | 'setContentType', |
||
488 | array('text/plain') |
||
489 | ), |
||
490 | array( |
||
491 | 'setDeliveryMode', |
||
492 | array(2) |
||
493 | ) |
||
494 | ), |
||
495 | $definition->getMethodCalls() |
||
496 | ); |
||
497 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
498 | } |
||
499 | |||
500 | public function testFooConsumerDefinition() |
||
501 | { |
||
502 | $container = $this->getContainer('test.yml'); |
||
503 | |||
504 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
||
505 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
||
506 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
507 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
||
508 | $this->assertEquals(array( |
||
509 | array( |
||
510 | 'setExchangeOptions', |
||
511 | array( |
||
512 | array( |
||
513 | 'name' => 'foo_exchange', |
||
514 | 'type' => 'direct', |
||
515 | 'passive' => true, |
||
516 | 'durable' => false, |
||
517 | 'auto_delete' => true, |
||
518 | 'internal' => true, |
||
519 | 'nowait' => true, |
||
520 | 'arguments' => null, |
||
521 | 'ticket' => null, |
||
522 | 'declare' => true, |
||
523 | ) |
||
524 | ) |
||
525 | ), |
||
526 | array( |
||
527 | 'setQueueOptions', |
||
528 | array( |
||
529 | array( |
||
530 | 'name' => 'foo_queue', |
||
531 | 'passive' => true, |
||
532 | 'durable' => false, |
||
533 | 'exclusive' => true, |
||
534 | 'auto_delete' => true, |
||
535 | 'nowait' => true, |
||
536 | 'arguments' => null, |
||
537 | 'ticket' => null, |
||
538 | 'routing_keys' => array('android.#.upload', 'iphone.upload'), |
||
539 | 'declare' => true, |
||
540 | ) |
||
541 | ) |
||
542 | ), |
||
543 | array( |
||
544 | 'setCallback', |
||
545 | array(array(new Reference('foo.callback'), 'execute')) |
||
546 | ), |
||
547 | array( |
||
548 | 'setTimeoutWait', |
||
549 | array(3) |
||
550 | ) |
||
551 | ), |
||
552 | $definition->getMethodCalls() |
||
553 | ); |
||
554 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
555 | } |
||
556 | |||
557 | public function testConsumerArgumentAliases() |
||
558 | { |
||
559 | /** @var ContainerBuilder $container */ |
||
560 | $container = $this->getContainer('test.yml'); |
||
561 | |||
562 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
563 | // don't test if autowiring arguments functionality is not available |
||
564 | return; |
||
565 | } |
||
566 | |||
567 | $expectedAliases = array( |
||
568 | ConsumerInterface::class . ' $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
569 | '%old_sound_rabbit_mq.consumer.class% $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
570 | ConsumerInterface::class . ' $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
571 | '%old_sound_rabbit_mq.consumer.class% $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
572 | ConsumerInterface::class . ' $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer', |
||
573 | '%old_sound_rabbit_mq.consumer.class% $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer' |
||
574 | ); |
||
575 | foreach($expectedAliases as $id => $target) { |
||
576 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
577 | |||
578 | $alias = $container->getAlias($id); |
||
579 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
580 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
581 | } |
||
582 | } |
||
583 | |||
584 | public function testDefaultConsumerDefinition() |
||
585 | { |
||
586 | $container = $this->getContainer('test.yml'); |
||
587 | |||
588 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
||
589 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
590 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
591 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
||
592 | $this->assertEquals(array( |
||
593 | array( |
||
594 | 'setExchangeOptions', |
||
595 | array( |
||
596 | array( |
||
597 | 'name' => 'default_exchange', |
||
598 | 'type' => 'direct', |
||
599 | 'passive' => false, |
||
600 | 'durable' => true, |
||
601 | 'auto_delete' => false, |
||
602 | 'internal' => false, |
||
603 | 'nowait' => false, |
||
604 | 'arguments' => null, |
||
605 | 'ticket' => null, |
||
606 | 'declare' => true, |
||
607 | ) |
||
608 | ) |
||
609 | ), |
||
610 | array( |
||
611 | 'setQueueOptions', |
||
612 | array( |
||
613 | array( |
||
614 | 'name' => 'default_queue', |
||
615 | 'passive' => false, |
||
616 | 'durable' => true, |
||
617 | 'exclusive' => false, |
||
618 | 'auto_delete' => false, |
||
619 | 'nowait' => false, |
||
620 | 'arguments' => null, |
||
621 | 'ticket' => null, |
||
622 | 'routing_keys' => array(), |
||
623 | 'declare' => true, |
||
624 | ) |
||
625 | ) |
||
626 | ), |
||
627 | array( |
||
628 | 'setCallback', |
||
629 | array(array(new Reference('default.callback'), 'execute')) |
||
630 | ) |
||
631 | ), |
||
632 | $definition->getMethodCalls() |
||
633 | ); |
||
634 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
635 | } |
||
636 | |||
637 | public function testConsumerWithQosOptions() |
||
638 | { |
||
639 | $container = $this->getContainer('test.yml'); |
||
640 | |||
641 | $this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
||
642 | $definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
||
643 | $methodCalls = $definition->getMethodCalls(); |
||
644 | |||
645 | $setQosParameters = null; |
||
646 | foreach ($methodCalls as $methodCall) { |
||
647 | if ($methodCall[0] === 'setQosOptions') { |
||
648 | $setQosParameters = $methodCall[1]; |
||
649 | } |
||
650 | } |
||
651 | |||
652 | $this->assertIsArray($setQosParameters); |
||
653 | $this->assertEquals( |
||
654 | array( |
||
655 | 1024, |
||
656 | 1, |
||
657 | true |
||
658 | ), |
||
659 | $setQosParameters |
||
660 | ); |
||
661 | } |
||
662 | |||
663 | public function testMultipleConsumerDefinition() |
||
664 | { |
||
665 | $container = $this->getContainer('test.yml'); |
||
666 | |||
667 | $this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
||
668 | $definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
||
669 | $this->assertEquals(array( |
||
670 | array( |
||
671 | 'setExchangeOptions', |
||
672 | array( |
||
673 | array( |
||
674 | 'name' => 'foo_multiple_exchange', |
||
675 | 'type' => 'direct', |
||
676 | 'passive' => false, |
||
677 | 'durable' => true, |
||
678 | 'auto_delete' => false, |
||
679 | 'internal' => false, |
||
680 | 'nowait' => false, |
||
681 | 'arguments' => null, |
||
682 | 'ticket' => null, |
||
683 | 'declare' => true, |
||
684 | ) |
||
685 | ) |
||
686 | ), |
||
687 | array( |
||
688 | 'setQueues', |
||
689 | array( |
||
690 | array( |
||
691 | 'multi_test_1' => array( |
||
692 | 'name' => 'multi_test_1', |
||
693 | 'passive' => false, |
||
694 | 'durable' => true, |
||
695 | 'exclusive' => false, |
||
696 | 'auto_delete' => false, |
||
697 | 'nowait' => false, |
||
698 | 'arguments' => null, |
||
699 | 'ticket' => null, |
||
700 | 'routing_keys' => array(), |
||
701 | 'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
||
702 | 'declare' => true, |
||
703 | ), |
||
704 | 'foo_bar_2' => array( |
||
705 | 'name' => 'foo_bar_2', |
||
706 | 'passive' => true, |
||
707 | 'durable' => false, |
||
708 | 'exclusive' => true, |
||
709 | 'auto_delete' => true, |
||
710 | 'nowait' => true, |
||
711 | 'arguments' => null, |
||
712 | 'ticket' => null, |
||
713 | 'routing_keys' => array( |
||
714 | 'android.upload', |
||
715 | 'iphone.upload' |
||
716 | ), |
||
717 | 'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
||
718 | 'declare' => true, |
||
719 | ) |
||
720 | ) |
||
721 | ) |
||
722 | ), |
||
723 | array( |
||
724 | 'setQueuesProvider', |
||
725 | array( |
||
726 | new Reference('foo.queues_provider') |
||
727 | ) |
||
728 | ), |
||
729 | array( |
||
730 | 'setTimeoutWait', |
||
731 | array(3) |
||
732 | ) |
||
733 | ), |
||
734 | $definition->getMethodCalls() |
||
735 | ); |
||
736 | } |
||
737 | |||
738 | public function testDynamicConsumerDefinition() |
||
739 | { |
||
740 | $container = $this->getContainer('test.yml'); |
||
741 | |||
742 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
||
743 | $this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
||
744 | |||
745 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
||
746 | $this->assertEquals(array( |
||
747 | array( |
||
748 | 'setExchangeOptions', |
||
749 | array( |
||
750 | array( |
||
751 | 'name' => 'foo_dynamic_exchange', |
||
752 | 'type' => 'direct', |
||
753 | 'passive' => false, |
||
754 | 'durable' => true, |
||
755 | 'auto_delete' => false, |
||
756 | 'internal' => false, |
||
757 | 'nowait' => false, |
||
758 | 'declare' => true, |
||
759 | 'arguments' => NULL, |
||
760 | 'ticket' => NULL, |
||
761 | ) |
||
762 | ) |
||
763 | ), |
||
764 | array( |
||
765 | 'setCallback', |
||
766 | array( |
||
767 | array(new Reference('foo.dynamic.callback'), 'execute') |
||
768 | ) |
||
769 | ), |
||
770 | array( |
||
771 | 'setQueueOptionsProvider', |
||
772 | array( |
||
773 | new Reference('foo.dynamic.provider') |
||
774 | ) |
||
775 | ) |
||
776 | ), |
||
777 | $definition->getMethodCalls() |
||
778 | ); |
||
779 | } |
||
780 | |||
781 | public function testFooAnonConsumerDefinition() |
||
782 | { |
||
783 | $container = $this->getContainer('test.yml'); |
||
784 | |||
785 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
||
786 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
||
787 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
788 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
||
789 | $this->assertEquals(array( |
||
790 | array( |
||
791 | 'setExchangeOptions', |
||
792 | array( |
||
793 | array( |
||
794 | 'name' => 'foo_anon_exchange', |
||
795 | 'type' => 'direct', |
||
796 | 'passive' => true, |
||
797 | 'durable' => false, |
||
798 | 'auto_delete' => true, |
||
799 | 'internal' => true, |
||
800 | 'nowait' => true, |
||
801 | 'arguments' => null, |
||
802 | 'ticket' => null, |
||
803 | 'declare' => true, |
||
804 | ) |
||
805 | ) |
||
806 | ), |
||
807 | array( |
||
808 | 'setCallback', |
||
809 | array(array(new Reference('foo_anon.callback'), 'execute')) |
||
810 | ) |
||
811 | ), |
||
812 | $definition->getMethodCalls() |
||
813 | ); |
||
814 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
815 | } |
||
816 | |||
817 | public function testDefaultAnonConsumerDefinition() |
||
818 | { |
||
819 | $container = $this->getContainer('test.yml'); |
||
820 | |||
821 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
||
822 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
||
823 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
824 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
||
825 | $this->assertEquals(array( |
||
826 | array( |
||
827 | 'setExchangeOptions', |
||
828 | array( |
||
829 | array( |
||
830 | 'name' => 'default_anon_exchange', |
||
831 | 'type' => 'direct', |
||
832 | 'passive' => false, |
||
833 | 'durable' => true, |
||
834 | 'auto_delete' => false, |
||
835 | 'internal' => false, |
||
836 | 'nowait' => false, |
||
837 | 'arguments' => null, |
||
838 | 'ticket' => null, |
||
839 | 'declare' => true, |
||
840 | ) |
||
841 | ) |
||
842 | ), |
||
843 | array( |
||
844 | 'setCallback', |
||
845 | array(array(new Reference('default_anon.callback'), 'execute')) |
||
846 | ) |
||
847 | ), |
||
848 | $definition->getMethodCalls() |
||
849 | ); |
||
850 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
851 | } |
||
852 | |||
853 | public function testFooRpcClientDefinition() |
||
854 | { |
||
855 | $container = $this->getContainer('rpc-clients.yml'); |
||
856 | |||
857 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
||
858 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
||
859 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
860 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
||
861 | $this->assertEquals( |
||
862 | array( |
||
863 | array('initClient', array(true)), |
||
864 | array('setUnserializer', array('json_decode')), |
||
865 | array('setDirectReplyTo', array(true)), |
||
866 | ), |
||
867 | $definition->getMethodCalls() |
||
868 | ); |
||
869 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
870 | } |
||
871 | |||
872 | public function testDefaultRpcClientDefinition() |
||
890 | } |
||
891 | |||
892 | public function testLazyRpcClientDefinition() |
||
893 | { |
||
894 | $container = $this->getContainer('rpc-clients.yml'); |
||
895 | |||
896 | $this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
||
897 | $definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
||
898 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
899 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
||
900 | $this->assertEquals( |
||
901 | array( |
||
902 | array('initClient', array(true)), |
||
903 | array('setUnserializer', array('unserialize')), |
||
904 | array('setDirectReplyTo', array(false)), |
||
905 | ), |
||
906 | $definition->getMethodCalls() |
||
907 | ); |
||
908 | $this->assertTrue($definition->isLazy()); |
||
909 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
910 | } |
||
911 | |||
912 | public function testFooRpcServerDefinition() |
||
913 | { |
||
914 | $container = $this->getContainer('test.yml'); |
||
915 | |||
916 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
||
917 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
||
918 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
919 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
||
920 | $this->assertEquals(array( |
||
921 | array('initServer', array('foo_server')), |
||
922 | array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
||
923 | array('setSerializer', array('json_encode')), |
||
924 | ), |
||
925 | $definition->getMethodCalls() |
||
926 | ); |
||
927 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
928 | } |
||
929 | |||
930 | public function testDefaultRpcServerDefinition() |
||
931 | { |
||
932 | $container = $this->getContainer('test.yml'); |
||
933 | |||
934 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
||
935 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
||
936 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
937 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
||
938 | $this->assertEquals(array( |
||
939 | array('initServer', array('default_server')), |
||
940 | array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
||
941 | array('setSerializer', array('serialize')), |
||
942 | ), |
||
943 | $definition->getMethodCalls() |
||
944 | ); |
||
945 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
946 | } |
||
947 | |||
948 | public function testRpcServerWithQueueOptionsDefinition() |
||
949 | { |
||
950 | $container = $this->getContainer('test.yml'); |
||
951 | |||
952 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
||
953 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server'); |
||
954 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
955 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options'); |
||
956 | $this->assertEquals(array( |
||
957 | array('initServer', array('server_with_queue_options')), |
||
958 | array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
||
959 | array('setQueueOptions', array(array( |
||
960 | 'name' => 'server_with_queue_options-queue', |
||
961 | 'passive' => false, |
||
962 | 'durable' => true, |
||
963 | 'exclusive' => false, |
||
964 | 'auto_delete' => false, |
||
965 | 'nowait' => false, |
||
966 | 'arguments' => null, |
||
967 | 'ticket' => null, |
||
968 | 'routing_keys' => array(), |
||
969 | 'declare' => true, |
||
970 | ))), |
||
971 | array('setSerializer', array('serialize')), |
||
972 | ), |
||
973 | $definition->getMethodCalls() |
||
974 | ); |
||
975 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
976 | } |
||
977 | |||
978 | public function testRpcServerWithExchangeOptionsDefinition() |
||
979 | { |
||
980 | $container = $this->getContainer('test.yml'); |
||
981 | |||
982 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
||
983 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
||
984 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
985 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
||
986 | $this->assertEquals(array( |
||
987 | array('initServer', array('server_with_exchange_options')), |
||
988 | array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
||
989 | array('setExchangeOptions', array(array( |
||
990 | 'name' => 'exchange', |
||
991 | 'type' => 'topic', |
||
992 | 'passive' => false, |
||
993 | 'durable' => true, |
||
994 | 'auto_delete' => false, |
||
995 | 'internal' => null, |
||
996 | 'nowait' => false, |
||
997 | 'declare' => true, |
||
998 | 'arguments' => null, |
||
999 | 'ticket' => null, |
||
1000 | ))), |
||
1001 | array('setSerializer', array('serialize')), |
||
1002 | ), |
||
1003 | $definition->getMethodCalls() |
||
1004 | ); |
||
1005 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
1006 | } |
||
1007 | |||
1008 | public function testHasCollectorWhenChannelsExist() |
||
1009 | { |
||
1010 | $container = $this->getContainer('collector.yml'); |
||
1011 | |||
1012 | $this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
||
1013 | $definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
||
1014 | |||
1015 | $this->assertEquals(array( |
||
1016 | new Reference('old_sound_rabbit_mq.channel.default_producer'), |
||
1017 | new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
||
1018 | ), |
||
1019 | $definition->getArgument(0) |
||
1020 | ); |
||
1021 | } |
||
1022 | |||
1023 | public function testHasNoCollectorWhenNoChannelsExist() |
||
1024 | { |
||
1025 | $container = $this->getContainer('no_collector.yml'); |
||
1026 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
1027 | } |
||
1028 | |||
1029 | public function testCollectorCanBeDisabled() |
||
1033 | } |
||
1034 | |||
1035 | public function testExchangeArgumentsAreArray() |
||
1050 | } |
||
1051 | |||
1052 | public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
||
1053 | { |
||
1054 | $container = $this->getContainer('no_exchange_options.yml'); |
||
1055 | |||
1056 | $definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
||
1057 | $calls = $definition->getMethodCalls(); |
||
1058 | $this->assertEquals('setExchangeOptions', $calls[0][0]); |
||
1059 | $options = $calls[0][1]; |
||
1060 | |||
1061 | $this->assertEquals('', $options[0]['name']); |
||
1062 | $this->assertEquals('direct', $options[0]['type']); |
||
1063 | $this->assertEquals(false, $options[0]['declare']); |
||
1064 | $this->assertEquals(true, $options[0]['passive']); |
||
1065 | } |
||
1066 | |||
1067 | public function testProducersWithLogger() |
||
1068 | { |
||
1069 | $container = $this->getContainer('config_with_enable_logger.yml'); |
||
1070 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
1071 | $this->assertTrue( |
||
1072 | $definition->hasTag('monolog.logger'), 'service should be marked for logger' |
||
1073 | ); |
||
1074 | } |
||
1075 | |||
1076 | private function getContainer($file, $debug = false) |
||
1090 | } |
||
1091 | } |
||
1092 |