Total Complexity | 43 |
Total Lines | 1089 |
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() |
||
215 | } |
||
216 | |||
217 | public function testMooBinding() |
||
237 | } |
||
238 | |||
239 | protected function assertBindingMethodCalls(Definition $definition, $binding) |
||
240 | { |
||
281 | ); |
||
282 | } |
||
283 | public function testFooProducerDefinition() |
||
284 | { |
||
285 | $container = $this->getContainer('test.yml'); |
||
286 | |||
287 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
||
288 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_producer_producer'); |
||
289 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
290 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_producer'); |
||
291 | $this->assertEquals( |
||
292 | array( |
||
293 | array( |
||
294 | 'setExchangeOptions', |
||
295 | array( |
||
296 | array( |
||
297 | 'name' => 'foo_exchange', |
||
298 | 'type' => 'direct', |
||
299 | 'passive' => true, |
||
300 | 'durable' => false, |
||
301 | 'auto_delete' => true, |
||
302 | 'internal' => true, |
||
303 | 'nowait' => true, |
||
304 | 'arguments' => null, |
||
305 | 'ticket' => null, |
||
306 | 'declare' => true, |
||
307 | ) |
||
308 | ) |
||
309 | ), |
||
310 | array( |
||
311 | 'setQueueOptions', |
||
312 | array( |
||
313 | array( |
||
314 | 'name' => '', |
||
315 | 'declare' => false, |
||
316 | ) |
||
317 | ) |
||
318 | ), |
||
319 | array( |
||
320 | 'setConfirmationTimeout', |
||
321 | array( |
||
322 | 0 |
||
323 | ) |
||
324 | ), |
||
325 | array( |
||
326 | 'setDefaultRoutingKey', |
||
327 | array('') |
||
328 | ), |
||
329 | array( |
||
330 | 'setContentType', |
||
331 | array('text/plain') |
||
332 | ), |
||
333 | array( |
||
334 | 'setDeliveryMode', |
||
335 | array(2) |
||
336 | ) |
||
337 | |||
338 | ), |
||
339 | $definition->getMethodCalls() |
||
340 | ); |
||
341 | $this->assertEquals('My\Foo\Producer', $definition->getClass()); |
||
342 | } |
||
343 | |||
344 | public function testProducerArgumentAliases() |
||
345 | { |
||
346 | /** @var ContainerBuilder $container */ |
||
347 | $container = $this->getContainer('test.yml'); |
||
348 | |||
349 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
350 | // don't test if autowiring arguments functionality is not available |
||
351 | return; |
||
352 | } |
||
353 | |||
354 | // test expected aliases |
||
355 | $expectedAliases = array( |
||
356 | ProducerInterface::class . ' $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
357 | 'My\Foo\Producer $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
358 | ProducerInterface::class . ' $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
359 | 'My\Foo\Producer $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
360 | ProducerInterface::class . ' $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
361 | '%old_sound_rabbit_mq.producer.class% $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
362 | ); |
||
363 | |||
364 | foreach ($expectedAliases as $id => $target) { |
||
365 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
366 | |||
367 | $alias = $container->getAlias($id); |
||
368 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
369 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
370 | } |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * @group alias |
||
375 | */ |
||
376 | public function testAliasedFooProducerDefinition() |
||
377 | { |
||
378 | $container = $this->getContainer('test.yml'); |
||
379 | |||
380 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
||
381 | $this->assertTrue($container->has('foo_producer_alias')); |
||
382 | } |
||
383 | |||
384 | public function testDefaultProducerDefinition() |
||
385 | { |
||
386 | $container = $this->getContainer('test.yml'); |
||
387 | |||
388 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_producer_producer')); |
||
389 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_producer_producer'); |
||
390 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
391 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_producer'); |
||
392 | $this->assertEquals( |
||
393 | array( |
||
394 | array( |
||
395 | 'setExchangeOptions', |
||
396 | array( |
||
397 | array( |
||
398 | 'name' => 'default_exchange', |
||
399 | 'type' => 'direct', |
||
400 | 'passive' => false, |
||
401 | 'durable' => true, |
||
402 | 'auto_delete' => false, |
||
403 | 'internal' => false, |
||
404 | 'nowait' => false, |
||
405 | 'arguments' => null, |
||
406 | 'ticket' => null, |
||
407 | 'declare' => true, |
||
408 | ) |
||
409 | ) |
||
410 | ), |
||
411 | array( |
||
412 | 'setQueueOptions', |
||
413 | array( |
||
414 | array( |
||
415 | 'name' => '', |
||
416 | 'declare' => false, |
||
417 | ) |
||
418 | ) |
||
419 | ), |
||
420 | array( |
||
421 | 'setConfirmationTimeout', |
||
422 | array( |
||
423 | 0 |
||
424 | ) |
||
425 | ), |
||
426 | array( |
||
427 | 'setDefaultRoutingKey', |
||
428 | array('') |
||
429 | ), |
||
430 | array( |
||
431 | 'setContentType', |
||
432 | array('text/plain') |
||
433 | ), |
||
434 | array( |
||
435 | 'setDeliveryMode', |
||
436 | array(2) |
||
437 | ) |
||
438 | ), |
||
439 | $definition->getMethodCalls() |
||
440 | ); |
||
441 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
442 | } |
||
443 | |||
444 | public function testConfirmatioProducerDefinition() |
||
445 | { |
||
446 | $container = $this->getContainer('test.yml'); |
||
447 | |||
448 | $this->assertTrue($container->has('old_sound_rabbit_mq.confirmation_producer_producer')); |
||
449 | $definition = $container->getDefinition('old_sound_rabbit_mq.confirmation_producer_producer'); |
||
450 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
451 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.confirmation_producer'); |
||
452 | $this->assertEquals(array( |
||
453 | array( |
||
454 | 'setExchangeOptions', |
||
455 | array( |
||
456 | array( |
||
457 | 'name' => 'default_exchange', |
||
458 | 'type' => 'direct', |
||
459 | 'passive' => false, |
||
460 | 'durable' => true, |
||
461 | 'auto_delete' => false, |
||
462 | 'internal' => false, |
||
463 | 'nowait' => false, |
||
464 | 'arguments' => null, |
||
465 | 'ticket' => null, |
||
466 | 'declare' => true, |
||
467 | ) |
||
468 | ) |
||
469 | ), |
||
470 | array( |
||
471 | 'setQueueOptions', |
||
472 | array( |
||
473 | array( |
||
474 | 'name' => '', |
||
475 | 'declare' => false, |
||
476 | ) |
||
477 | ) |
||
478 | ), |
||
479 | array( |
||
480 | 'setConfirmationTimeout', |
||
481 | array( |
||
482 | 2 |
||
483 | ) |
||
484 | ), |
||
485 | array( |
||
486 | 'setDefaultRoutingKey', |
||
487 | array('') |
||
488 | ), |
||
489 | array( |
||
490 | 'setContentType', |
||
491 | array('text/plain') |
||
492 | ), |
||
493 | array( |
||
494 | 'setDeliveryMode', |
||
495 | array(2) |
||
496 | ) |
||
497 | ), |
||
498 | $definition->getMethodCalls() |
||
499 | ); |
||
500 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
501 | } |
||
502 | |||
503 | public function testFooConsumerDefinition() |
||
504 | { |
||
505 | $container = $this->getContainer('test.yml'); |
||
506 | |||
507 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
||
508 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
||
509 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
510 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
||
511 | $this->assertEquals( |
||
512 | array( |
||
513 | array( |
||
514 | 'setExchangeOptions', |
||
515 | array( |
||
516 | array( |
||
517 | 'name' => 'foo_exchange', |
||
518 | 'type' => 'direct', |
||
519 | 'passive' => true, |
||
520 | 'durable' => false, |
||
521 | 'auto_delete' => true, |
||
522 | 'internal' => true, |
||
523 | 'nowait' => true, |
||
524 | 'arguments' => null, |
||
525 | 'ticket' => null, |
||
526 | 'declare' => true, |
||
527 | ) |
||
528 | ) |
||
529 | ), |
||
530 | array( |
||
531 | 'setQueueOptions', |
||
532 | array( |
||
533 | array( |
||
534 | 'name' => 'foo_queue', |
||
535 | 'passive' => true, |
||
536 | 'durable' => false, |
||
537 | 'exclusive' => true, |
||
538 | 'auto_delete' => true, |
||
539 | 'nowait' => true, |
||
540 | 'arguments' => null, |
||
541 | 'ticket' => null, |
||
542 | 'routing_keys' => array('android.#.upload', 'iphone.upload'), |
||
543 | 'declare' => true, |
||
544 | ) |
||
545 | ) |
||
546 | ), |
||
547 | array( |
||
548 | 'setCallback', |
||
549 | array(array(new Reference('foo.callback'), 'execute')) |
||
550 | ), |
||
551 | array( |
||
552 | 'setTimeoutWait', |
||
553 | array(3) |
||
554 | ) |
||
555 | ), |
||
556 | $definition->getMethodCalls() |
||
557 | ); |
||
558 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
559 | } |
||
560 | |||
561 | public function testConsumerArgumentAliases() |
||
562 | { |
||
563 | /** @var ContainerBuilder $container */ |
||
564 | $container = $this->getContainer('test.yml'); |
||
565 | |||
566 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
567 | // don't test if autowiring arguments functionality is not available |
||
568 | return; |
||
569 | } |
||
570 | |||
571 | $expectedAliases = array( |
||
572 | ConsumerInterface::class . ' $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
573 | '%old_sound_rabbit_mq.consumer.class% $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
574 | ConsumerInterface::class . ' $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
575 | '%old_sound_rabbit_mq.consumer.class% $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
576 | ConsumerInterface::class . ' $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer', |
||
577 | '%old_sound_rabbit_mq.consumer.class% $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer' |
||
578 | ); |
||
579 | foreach ($expectedAliases as $id => $target) { |
||
580 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
581 | |||
582 | $alias = $container->getAlias($id); |
||
583 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
584 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
585 | } |
||
586 | } |
||
587 | |||
588 | public function testDefaultConsumerDefinition() |
||
589 | { |
||
590 | $container = $this->getContainer('test.yml'); |
||
591 | |||
592 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
||
593 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
594 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
595 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
||
596 | $this->assertEquals( |
||
597 | array( |
||
598 | array( |
||
599 | 'setExchangeOptions', |
||
600 | array( |
||
601 | array( |
||
602 | 'name' => 'default_exchange', |
||
603 | 'type' => 'direct', |
||
604 | 'passive' => false, |
||
605 | 'durable' => true, |
||
606 | 'auto_delete' => false, |
||
607 | 'internal' => false, |
||
608 | 'nowait' => false, |
||
609 | 'arguments' => null, |
||
610 | 'ticket' => null, |
||
611 | 'declare' => true, |
||
612 | ) |
||
613 | ) |
||
614 | ), |
||
615 | array( |
||
616 | 'setQueueOptions', |
||
617 | array( |
||
618 | array( |
||
619 | 'name' => 'default_queue', |
||
620 | 'passive' => false, |
||
621 | 'durable' => true, |
||
622 | 'exclusive' => false, |
||
623 | 'auto_delete' => false, |
||
624 | 'nowait' => false, |
||
625 | 'arguments' => null, |
||
626 | 'ticket' => null, |
||
627 | 'routing_keys' => array(), |
||
628 | 'declare' => true, |
||
629 | ) |
||
630 | ) |
||
631 | ), |
||
632 | array( |
||
633 | 'setCallback', |
||
634 | array(array(new Reference('default.callback'), 'execute')) |
||
635 | ) |
||
636 | ), |
||
637 | $definition->getMethodCalls() |
||
638 | ); |
||
639 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
640 | } |
||
641 | |||
642 | public function testConsumerWithQosOptions() |
||
643 | { |
||
644 | $container = $this->getContainer('test.yml'); |
||
645 | |||
646 | $this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
||
647 | $definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
||
648 | $methodCalls = $definition->getMethodCalls(); |
||
649 | |||
650 | $setQosParameters = null; |
||
651 | foreach ($methodCalls as $methodCall) { |
||
652 | if ($methodCall[0] === 'setQosOptions') { |
||
653 | $setQosParameters = $methodCall[1]; |
||
654 | } |
||
655 | } |
||
656 | |||
657 | $this->assertIsArray($setQosParameters); |
||
658 | $this->assertEquals( |
||
659 | array( |
||
660 | 1024, |
||
661 | 1, |
||
662 | true |
||
663 | ), |
||
664 | $setQosParameters |
||
665 | ); |
||
666 | } |
||
667 | |||
668 | public function testMultipleConsumerDefinition() |
||
669 | { |
||
670 | $container = $this->getContainer('test.yml'); |
||
671 | |||
672 | $this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
||
673 | $definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
||
674 | $this->assertEquals( |
||
675 | array( |
||
676 | array( |
||
677 | 'setExchangeOptions', |
||
678 | array( |
||
679 | array( |
||
680 | 'name' => 'foo_multiple_exchange', |
||
681 | 'type' => 'direct', |
||
682 | 'passive' => false, |
||
683 | 'durable' => true, |
||
684 | 'auto_delete' => false, |
||
685 | 'internal' => false, |
||
686 | 'nowait' => false, |
||
687 | 'arguments' => null, |
||
688 | 'ticket' => null, |
||
689 | 'declare' => true, |
||
690 | ) |
||
691 | ) |
||
692 | ), |
||
693 | array( |
||
694 | 'setQueues', |
||
695 | array( |
||
696 | array( |
||
697 | 'multi_test_1' => array( |
||
698 | 'name' => 'multi_test_1', |
||
699 | 'passive' => false, |
||
700 | 'durable' => true, |
||
701 | 'exclusive' => false, |
||
702 | 'auto_delete' => false, |
||
703 | 'nowait' => false, |
||
704 | 'arguments' => null, |
||
705 | 'ticket' => null, |
||
706 | 'routing_keys' => array(), |
||
707 | 'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
||
708 | 'declare' => true, |
||
709 | ), |
||
710 | 'foo_bar_2' => array( |
||
711 | 'name' => 'foo_bar_2', |
||
712 | 'passive' => true, |
||
713 | 'durable' => false, |
||
714 | 'exclusive' => true, |
||
715 | 'auto_delete' => true, |
||
716 | 'nowait' => true, |
||
717 | 'arguments' => null, |
||
718 | 'ticket' => null, |
||
719 | 'routing_keys' => array( |
||
720 | 'android.upload', |
||
721 | 'iphone.upload' |
||
722 | ), |
||
723 | 'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
||
724 | 'declare' => true, |
||
725 | ) |
||
726 | ) |
||
727 | ) |
||
728 | ), |
||
729 | array( |
||
730 | 'setQueuesProvider', |
||
731 | array( |
||
732 | new Reference('foo.queues_provider') |
||
733 | ) |
||
734 | ), |
||
735 | array( |
||
736 | 'setTimeoutWait', |
||
737 | array(3) |
||
738 | ) |
||
739 | ), |
||
740 | $definition->getMethodCalls() |
||
741 | ); |
||
742 | } |
||
743 | |||
744 | public function testDynamicConsumerDefinition() |
||
745 | { |
||
746 | $container = $this->getContainer('test.yml'); |
||
747 | |||
748 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
||
749 | $this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
||
750 | |||
751 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
||
752 | $this->assertEquals( |
||
753 | array( |
||
754 | array( |
||
755 | 'setExchangeOptions', |
||
756 | array( |
||
757 | array( |
||
758 | 'name' => 'foo_dynamic_exchange', |
||
759 | 'type' => 'direct', |
||
760 | 'passive' => false, |
||
761 | 'durable' => true, |
||
762 | 'auto_delete' => false, |
||
763 | 'internal' => false, |
||
764 | 'nowait' => false, |
||
765 | 'declare' => true, |
||
766 | 'arguments' => null, |
||
767 | 'ticket' => null, |
||
768 | ) |
||
769 | ) |
||
770 | ), |
||
771 | array( |
||
772 | 'setCallback', |
||
773 | array( |
||
774 | array(new Reference('foo.dynamic.callback'), 'execute') |
||
775 | ) |
||
776 | ), |
||
777 | array( |
||
778 | 'setQueueOptionsProvider', |
||
779 | array( |
||
780 | new Reference('foo.dynamic.provider') |
||
781 | ) |
||
782 | ) |
||
783 | ), |
||
784 | $definition->getMethodCalls() |
||
785 | ); |
||
786 | } |
||
787 | |||
788 | public function testFooAnonConsumerDefinition() |
||
789 | { |
||
790 | $container = $this->getContainer('test.yml'); |
||
791 | |||
792 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
||
793 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
||
794 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
795 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
||
796 | $this->assertEquals( |
||
797 | array( |
||
798 | array( |
||
799 | 'setExchangeOptions', |
||
800 | array( |
||
801 | array( |
||
802 | 'name' => 'foo_anon_exchange', |
||
803 | 'type' => 'direct', |
||
804 | 'passive' => true, |
||
805 | 'durable' => false, |
||
806 | 'auto_delete' => true, |
||
807 | 'internal' => true, |
||
808 | 'nowait' => true, |
||
809 | 'arguments' => null, |
||
810 | 'ticket' => null, |
||
811 | 'declare' => true, |
||
812 | ) |
||
813 | ) |
||
814 | ), |
||
815 | array( |
||
816 | 'setCallback', |
||
817 | array(array(new Reference('foo_anon.callback'), 'execute')) |
||
818 | ) |
||
819 | ), |
||
820 | $definition->getMethodCalls() |
||
821 | ); |
||
822 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
823 | } |
||
824 | |||
825 | public function testDefaultAnonConsumerDefinition() |
||
826 | { |
||
827 | $container = $this->getContainer('test.yml'); |
||
828 | |||
829 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
||
830 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
||
831 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
832 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
||
833 | $this->assertEquals( |
||
834 | array( |
||
835 | array( |
||
836 | 'setExchangeOptions', |
||
837 | array( |
||
838 | array( |
||
839 | 'name' => 'default_anon_exchange', |
||
840 | 'type' => 'direct', |
||
841 | 'passive' => false, |
||
842 | 'durable' => true, |
||
843 | 'auto_delete' => false, |
||
844 | 'internal' => false, |
||
845 | 'nowait' => false, |
||
846 | 'arguments' => null, |
||
847 | 'ticket' => null, |
||
848 | 'declare' => true, |
||
849 | ) |
||
850 | ) |
||
851 | ), |
||
852 | array( |
||
853 | 'setCallback', |
||
854 | array(array(new Reference('default_anon.callback'), 'execute')) |
||
855 | ) |
||
856 | ), |
||
857 | $definition->getMethodCalls() |
||
858 | ); |
||
859 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
860 | } |
||
861 | |||
862 | public function testFooRpcClientDefinition() |
||
863 | { |
||
864 | $container = $this->getContainer('rpc-clients.yml'); |
||
865 | |||
866 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
||
867 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
||
868 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
869 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
||
870 | $this->assertEquals( |
||
871 | array( |
||
872 | array('initClient', array(true)), |
||
873 | array('setUnserializer', array('json_decode')), |
||
874 | array('setDirectReplyTo', array(true)), |
||
875 | ), |
||
876 | $definition->getMethodCalls() |
||
877 | ); |
||
878 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
879 | } |
||
880 | |||
881 | public function testDefaultRpcClientDefinition() |
||
899 | } |
||
900 | |||
901 | public function testLazyRpcClientDefinition() |
||
902 | { |
||
903 | $container = $this->getContainer('rpc-clients.yml'); |
||
904 | |||
905 | $this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
||
906 | $definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
||
907 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
908 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
||
909 | $this->assertEquals( |
||
910 | array( |
||
911 | array('initClient', array(true)), |
||
912 | array('setUnserializer', array('unserialize')), |
||
913 | array('setDirectReplyTo', array(false)), |
||
914 | ), |
||
915 | $definition->getMethodCalls() |
||
916 | ); |
||
917 | $this->assertTrue($definition->isLazy()); |
||
918 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
919 | } |
||
920 | |||
921 | public function testFooRpcServerDefinition() |
||
922 | { |
||
923 | $container = $this->getContainer('test.yml'); |
||
924 | |||
925 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
||
926 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
||
927 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
928 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
||
929 | $this->assertEquals( |
||
930 | array( |
||
931 | array('initServer', array('foo_server')), |
||
932 | array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
||
933 | array('setSerializer', array('json_encode')), |
||
934 | ), |
||
935 | $definition->getMethodCalls() |
||
936 | ); |
||
937 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
938 | } |
||
939 | |||
940 | public function testDefaultRpcServerDefinition() |
||
941 | { |
||
942 | $container = $this->getContainer('test.yml'); |
||
943 | |||
944 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
||
945 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
||
946 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
947 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
||
948 | $this->assertEquals( |
||
949 | array( |
||
950 | array('initServer', array('default_server')), |
||
951 | array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
||
952 | array('setSerializer', array('serialize')), |
||
953 | ), |
||
954 | $definition->getMethodCalls() |
||
955 | ); |
||
956 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
957 | } |
||
958 | |||
959 | public function testRpcServerWithQueueOptionsDefinition() |
||
960 | { |
||
961 | $container = $this->getContainer('test.yml'); |
||
962 | |||
963 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
||
964 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server'); |
||
965 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
966 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options'); |
||
967 | $this->assertEquals( |
||
968 | array( |
||
969 | array('initServer', array('server_with_queue_options')), |
||
970 | array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
||
971 | array('setQueueOptions', array(array( |
||
972 | 'name' => 'server_with_queue_options-queue', |
||
973 | 'passive' => false, |
||
974 | 'durable' => true, |
||
975 | 'exclusive' => false, |
||
976 | 'auto_delete' => false, |
||
977 | 'nowait' => false, |
||
978 | 'arguments' => null, |
||
979 | 'ticket' => null, |
||
980 | 'routing_keys' => array(), |
||
981 | 'declare' => true, |
||
982 | ))), |
||
983 | array('setSerializer', array('serialize')), |
||
984 | ), |
||
985 | $definition->getMethodCalls() |
||
986 | ); |
||
987 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
988 | } |
||
989 | |||
990 | public function testRpcServerWithExchangeOptionsDefinition() |
||
991 | { |
||
992 | $container = $this->getContainer('test.yml'); |
||
993 | |||
994 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
||
995 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
||
996 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
997 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
||
998 | $this->assertEquals( |
||
999 | array( |
||
1000 | array('initServer', array('server_with_exchange_options')), |
||
1001 | array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
||
1002 | array('setExchangeOptions', array(array( |
||
1003 | 'name' => 'exchange', |
||
1004 | 'type' => 'topic', |
||
1005 | 'passive' => false, |
||
1006 | 'durable' => true, |
||
1007 | 'auto_delete' => false, |
||
1008 | 'internal' => null, |
||
1009 | 'nowait' => false, |
||
1010 | 'declare' => true, |
||
1011 | 'arguments' => null, |
||
1012 | 'ticket' => null, |
||
1013 | ))), |
||
1014 | array('setSerializer', array('serialize')), |
||
1015 | ), |
||
1016 | $definition->getMethodCalls() |
||
1017 | ); |
||
1018 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
1019 | } |
||
1020 | |||
1021 | public function testHasCollectorWhenChannelsExist() |
||
1022 | { |
||
1023 | $container = $this->getContainer('collector.yml'); |
||
1024 | |||
1025 | $this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
||
1026 | $definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
||
1027 | |||
1028 | $this->assertEquals( |
||
1029 | array( |
||
1030 | new Reference('old_sound_rabbit_mq.channel.default_producer'), |
||
1031 | new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
||
1032 | ), |
||
1033 | $definition->getArgument(0) |
||
1034 | ); |
||
1035 | } |
||
1036 | |||
1037 | public function testHasNoCollectorWhenNoChannelsExist() |
||
1038 | { |
||
1039 | $container = $this->getContainer('no_collector.yml'); |
||
1040 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
1041 | } |
||
1042 | |||
1043 | public function testCollectorCanBeDisabled() |
||
1047 | } |
||
1048 | |||
1049 | public function testExchangeArgumentsAreArray() |
||
1064 | } |
||
1065 | |||
1066 | public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
||
1067 | { |
||
1068 | $container = $this->getContainer('no_exchange_options.yml'); |
||
1069 | |||
1070 | $definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
||
1071 | $calls = $definition->getMethodCalls(); |
||
1072 | $this->assertEquals('setExchangeOptions', $calls[0][0]); |
||
1073 | $options = $calls[0][1]; |
||
1074 | |||
1075 | $this->assertEquals('', $options[0]['name']); |
||
1076 | $this->assertEquals('direct', $options[0]['type']); |
||
1077 | $this->assertEquals(false, $options[0]['declare']); |
||
1078 | $this->assertEquals(true, $options[0]['passive']); |
||
1079 | } |
||
1080 | |||
1081 | public function testProducersWithLogger() |
||
1082 | { |
||
1083 | $container = $this->getContainer('config_with_enable_logger.yml'); |
||
1084 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
1085 | $this->assertTrue( |
||
1086 | $definition->hasTag('monolog.logger'), |
||
1087 | 'service should be marked for logger' |
||
1088 | ); |
||
1089 | } |
||
1090 | |||
1091 | private function getContainer($file, $debug = false) |
||
1105 | } |
||
1106 | } |
||
1107 |