Total Complexity | 43 |
Total Lines | 1066 |
Duplicated Lines | 0 % |
Changes | 20 | ||
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() |
||
343 | { |
||
344 | /** @var ContainerBuilder $container */ |
||
345 | $container = $this->getContainer('test.yml'); |
||
346 | |||
347 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
348 | // don't test if autowiring arguments functionality is not available |
||
349 | return; |
||
350 | } |
||
351 | |||
352 | // test expected aliases |
||
353 | $expectedAliases = array( |
||
354 | ProducerInterface::class . ' $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
355 | 'My\Foo\Producer $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
356 | ProducerInterface::class . ' $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
357 | 'My\Foo\Producer $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
358 | ProducerInterface::class . ' $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
359 | '%old_sound_rabbit_mq.producer.class% $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
360 | ); |
||
361 | |||
362 | foreach($expectedAliases as $id => $target) { |
||
363 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
364 | |||
365 | $alias = $container->getAlias($id); |
||
366 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
367 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
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() |
||
383 | { |
||
384 | $container = $this->getContainer('test.yml'); |
||
385 | |||
386 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_producer_producer')); |
||
387 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_producer_producer'); |
||
388 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
389 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_producer'); |
||
390 | $this->assertEquals(array( |
||
391 | array( |
||
392 | 'setExchangeOptions', |
||
393 | array( |
||
394 | array( |
||
395 | 'name' => 'default_exchange', |
||
396 | 'type' => 'direct', |
||
397 | 'passive' => false, |
||
398 | 'durable' => true, |
||
399 | 'auto_delete' => false, |
||
400 | 'internal' => false, |
||
401 | 'nowait' => false, |
||
402 | 'arguments' => null, |
||
403 | 'ticket' => null, |
||
404 | 'declare' => true, |
||
405 | ) |
||
406 | ) |
||
407 | ), |
||
408 | array( |
||
409 | 'setQueueOptions', |
||
410 | array( |
||
411 | array( |
||
412 | 'name' => '', |
||
413 | 'declare' => false, |
||
414 | ) |
||
415 | ) |
||
416 | ), |
||
417 | array( |
||
418 | 'setConfirmationTimeout', |
||
419 | array( |
||
420 | 0 |
||
421 | ) |
||
422 | ), |
||
423 | array( |
||
424 | 'setDefaultRoutingKey', |
||
425 | array('') |
||
426 | ), |
||
427 | array( |
||
428 | 'setContentType', |
||
429 | array('text/plain') |
||
430 | ), |
||
431 | array( |
||
432 | 'setDeliveryMode', |
||
433 | array(2) |
||
434 | ) |
||
435 | ), |
||
436 | $definition->getMethodCalls() |
||
437 | ); |
||
438 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
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 | ), |
||
487 | $definition->getMethodCalls() |
||
488 | ); |
||
489 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
490 | } |
||
491 | |||
492 | public function testFooConsumerDefinition() |
||
493 | { |
||
494 | $container = $this->getContainer('test.yml'); |
||
495 | |||
496 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
||
497 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
||
498 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
499 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
||
500 | $this->assertEquals(array( |
||
501 | array( |
||
502 | 'setExchangeOptions', |
||
503 | array( |
||
504 | array( |
||
505 | 'name' => 'foo_exchange', |
||
506 | 'type' => 'direct', |
||
507 | 'passive' => true, |
||
508 | 'durable' => false, |
||
509 | 'auto_delete' => true, |
||
510 | 'internal' => true, |
||
511 | 'nowait' => true, |
||
512 | 'arguments' => null, |
||
513 | 'ticket' => null, |
||
514 | 'declare' => true, |
||
515 | ) |
||
516 | ) |
||
517 | ), |
||
518 | array( |
||
519 | 'setQueueOptions', |
||
520 | array( |
||
521 | array( |
||
522 | 'name' => 'foo_queue', |
||
523 | 'passive' => true, |
||
524 | 'durable' => false, |
||
525 | 'exclusive' => true, |
||
526 | 'auto_delete' => true, |
||
527 | 'nowait' => true, |
||
528 | 'arguments' => null, |
||
529 | 'ticket' => null, |
||
530 | 'routing_keys' => array('android.#.upload', 'iphone.upload'), |
||
531 | 'declare' => true, |
||
532 | ) |
||
533 | ) |
||
534 | ), |
||
535 | array( |
||
536 | 'setCallback', |
||
537 | array(array(new Reference('foo.callback'), 'execute')) |
||
538 | ), |
||
539 | array( |
||
540 | 'setTimeoutWait', |
||
541 | array(3) |
||
542 | ) |
||
543 | ), |
||
544 | $definition->getMethodCalls() |
||
545 | ); |
||
546 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
547 | } |
||
548 | |||
549 | public function testConsumerArgumentAliases() |
||
550 | { |
||
551 | /** @var ContainerBuilder $container */ |
||
552 | $container = $this->getContainer('test.yml'); |
||
553 | |||
554 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
555 | // don't test if autowiring arguments functionality is not available |
||
556 | return; |
||
557 | } |
||
558 | |||
559 | $expectedAliases = array( |
||
560 | ConsumerInterface::class . ' $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
561 | '%old_sound_rabbit_mq.consumer.class% $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
562 | ConsumerInterface::class . ' $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
563 | '%old_sound_rabbit_mq.consumer.class% $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
564 | ConsumerInterface::class . ' $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer', |
||
565 | '%old_sound_rabbit_mq.consumer.class% $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer' |
||
566 | ); |
||
567 | foreach($expectedAliases as $id => $target) { |
||
568 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
569 | |||
570 | $alias = $container->getAlias($id); |
||
571 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
572 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
573 | } |
||
574 | } |
||
575 | |||
576 | public function testDefaultConsumerDefinition() |
||
577 | { |
||
578 | $container = $this->getContainer('test.yml'); |
||
579 | |||
580 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
||
581 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
582 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
583 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
||
584 | $this->assertEquals(array( |
||
585 | array( |
||
586 | 'setExchangeOptions', |
||
587 | array( |
||
588 | array( |
||
589 | 'name' => 'default_exchange', |
||
590 | 'type' => 'direct', |
||
591 | 'passive' => false, |
||
592 | 'durable' => true, |
||
593 | 'auto_delete' => false, |
||
594 | 'internal' => false, |
||
595 | 'nowait' => false, |
||
596 | 'arguments' => null, |
||
597 | 'ticket' => null, |
||
598 | 'declare' => true, |
||
599 | ) |
||
600 | ) |
||
601 | ), |
||
602 | array( |
||
603 | 'setQueueOptions', |
||
604 | array( |
||
605 | array( |
||
606 | 'name' => 'default_queue', |
||
607 | 'passive' => false, |
||
608 | 'durable' => true, |
||
609 | 'exclusive' => false, |
||
610 | 'auto_delete' => false, |
||
611 | 'nowait' => false, |
||
612 | 'arguments' => null, |
||
613 | 'ticket' => null, |
||
614 | 'routing_keys' => array(), |
||
615 | 'declare' => true, |
||
616 | ) |
||
617 | ) |
||
618 | ), |
||
619 | array( |
||
620 | 'setCallback', |
||
621 | array(array(new Reference('default.callback'), 'execute')) |
||
622 | ) |
||
623 | ), |
||
624 | $definition->getMethodCalls() |
||
625 | ); |
||
626 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
627 | } |
||
628 | |||
629 | public function testConsumerWithQosOptions() |
||
630 | { |
||
631 | $container = $this->getContainer('test.yml'); |
||
632 | |||
633 | $this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
||
634 | $definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
||
635 | $methodCalls = $definition->getMethodCalls(); |
||
636 | |||
637 | $setQosParameters = null; |
||
638 | foreach ($methodCalls as $methodCall) { |
||
639 | if ($methodCall[0] === 'setQosOptions') { |
||
640 | $setQosParameters = $methodCall[1]; |
||
641 | } |
||
642 | } |
||
643 | |||
644 | $this->assertIsArray($setQosParameters); |
||
645 | $this->assertEquals( |
||
646 | array( |
||
647 | 1024, |
||
648 | 1, |
||
649 | true |
||
650 | ), |
||
651 | $setQosParameters |
||
652 | ); |
||
653 | } |
||
654 | |||
655 | public function testMultipleConsumerDefinition() |
||
656 | { |
||
657 | $container = $this->getContainer('test.yml'); |
||
658 | |||
659 | $this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
||
660 | $definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
||
661 | $this->assertEquals(array( |
||
662 | array( |
||
663 | 'setExchangeOptions', |
||
664 | array( |
||
665 | array( |
||
666 | 'name' => 'foo_multiple_exchange', |
||
667 | 'type' => 'direct', |
||
668 | 'passive' => false, |
||
669 | 'durable' => true, |
||
670 | 'auto_delete' => false, |
||
671 | 'internal' => false, |
||
672 | 'nowait' => false, |
||
673 | 'arguments' => null, |
||
674 | 'ticket' => null, |
||
675 | 'declare' => true, |
||
676 | ) |
||
677 | ) |
||
678 | ), |
||
679 | array( |
||
680 | 'setQueues', |
||
681 | array( |
||
682 | array( |
||
683 | 'multi_test_1' => array( |
||
684 | 'name' => 'multi_test_1', |
||
685 | 'passive' => false, |
||
686 | 'durable' => true, |
||
687 | 'exclusive' => false, |
||
688 | 'auto_delete' => false, |
||
689 | 'nowait' => false, |
||
690 | 'arguments' => null, |
||
691 | 'ticket' => null, |
||
692 | 'routing_keys' => array(), |
||
693 | 'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
||
694 | 'declare' => true, |
||
695 | ), |
||
696 | 'foo_bar_2' => array( |
||
697 | 'name' => 'foo_bar_2', |
||
698 | 'passive' => true, |
||
699 | 'durable' => false, |
||
700 | 'exclusive' => true, |
||
701 | 'auto_delete' => true, |
||
702 | 'nowait' => true, |
||
703 | 'arguments' => null, |
||
704 | 'ticket' => null, |
||
705 | 'routing_keys' => array( |
||
706 | 'android.upload', |
||
707 | 'iphone.upload' |
||
708 | ), |
||
709 | 'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
||
710 | 'declare' => true, |
||
711 | ) |
||
712 | ) |
||
713 | ) |
||
714 | ), |
||
715 | array( |
||
716 | 'setQueuesProvider', |
||
717 | array( |
||
718 | new Reference('foo.queues_provider') |
||
719 | ) |
||
720 | ), |
||
721 | array( |
||
722 | 'setTimeoutWait', |
||
723 | array(3) |
||
724 | ) |
||
725 | ), |
||
726 | $definition->getMethodCalls() |
||
727 | ); |
||
728 | } |
||
729 | |||
730 | public function testDynamicConsumerDefinition() |
||
731 | { |
||
732 | $container = $this->getContainer('test.yml'); |
||
733 | |||
734 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
||
735 | $this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
||
736 | |||
737 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
||
738 | $this->assertEquals(array( |
||
739 | array( |
||
740 | 'setExchangeOptions', |
||
741 | array( |
||
742 | array( |
||
743 | 'name' => 'foo_dynamic_exchange', |
||
744 | 'type' => 'direct', |
||
745 | 'passive' => false, |
||
746 | 'durable' => true, |
||
747 | 'auto_delete' => false, |
||
748 | 'internal' => false, |
||
749 | 'nowait' => false, |
||
750 | 'declare' => true, |
||
751 | 'arguments' => NULL, |
||
752 | 'ticket' => NULL, |
||
753 | ) |
||
754 | ) |
||
755 | ), |
||
756 | array( |
||
757 | 'setCallback', |
||
758 | array( |
||
759 | array(new Reference('foo.dynamic.callback'), 'execute') |
||
760 | ) |
||
761 | ), |
||
762 | array( |
||
763 | 'setQueueOptionsProvider', |
||
764 | array( |
||
765 | new Reference('foo.dynamic.provider') |
||
766 | ) |
||
767 | ) |
||
768 | ), |
||
769 | $definition->getMethodCalls() |
||
770 | ); |
||
771 | } |
||
772 | |||
773 | public function testFooAnonConsumerDefinition() |
||
774 | { |
||
775 | $container = $this->getContainer('test.yml'); |
||
776 | |||
777 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
||
778 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
||
779 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
780 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
||
781 | $this->assertEquals(array( |
||
782 | array( |
||
783 | 'setExchangeOptions', |
||
784 | array( |
||
785 | array( |
||
786 | 'name' => 'foo_anon_exchange', |
||
787 | 'type' => 'direct', |
||
788 | 'passive' => true, |
||
789 | 'durable' => false, |
||
790 | 'auto_delete' => true, |
||
791 | 'internal' => true, |
||
792 | 'nowait' => true, |
||
793 | 'arguments' => null, |
||
794 | 'ticket' => null, |
||
795 | 'declare' => true, |
||
796 | ) |
||
797 | ) |
||
798 | ), |
||
799 | array( |
||
800 | 'setCallback', |
||
801 | array(array(new Reference('foo_anon.callback'), 'execute')) |
||
802 | ) |
||
803 | ), |
||
804 | $definition->getMethodCalls() |
||
805 | ); |
||
806 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
807 | } |
||
808 | |||
809 | public function testDefaultAnonConsumerDefinition() |
||
810 | { |
||
811 | $container = $this->getContainer('test.yml'); |
||
812 | |||
813 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
||
814 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
||
815 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
816 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
||
817 | $this->assertEquals(array( |
||
818 | array( |
||
819 | 'setExchangeOptions', |
||
820 | array( |
||
821 | array( |
||
822 | 'name' => 'default_anon_exchange', |
||
823 | 'type' => 'direct', |
||
824 | 'passive' => false, |
||
825 | 'durable' => true, |
||
826 | 'auto_delete' => false, |
||
827 | 'internal' => false, |
||
828 | 'nowait' => false, |
||
829 | 'arguments' => null, |
||
830 | 'ticket' => null, |
||
831 | 'declare' => true, |
||
832 | ) |
||
833 | ) |
||
834 | ), |
||
835 | array( |
||
836 | 'setCallback', |
||
837 | array(array(new Reference('default_anon.callback'), 'execute')) |
||
838 | ) |
||
839 | ), |
||
840 | $definition->getMethodCalls() |
||
841 | ); |
||
842 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
843 | } |
||
844 | |||
845 | public function testFooRpcClientDefinition() |
||
846 | { |
||
847 | $container = $this->getContainer('rpc-clients.yml'); |
||
848 | |||
849 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
||
850 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
||
851 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
852 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
||
853 | $this->assertEquals( |
||
854 | array( |
||
855 | array('initClient', array(true)), |
||
856 | array('setUnserializer', array('json_decode')), |
||
857 | array('setDirectReplyTo', array(true)), |
||
858 | ), |
||
859 | $definition->getMethodCalls() |
||
860 | ); |
||
861 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
862 | } |
||
863 | |||
864 | public function testDefaultRpcClientDefinition() |
||
882 | } |
||
883 | |||
884 | public function testLazyRpcClientDefinition() |
||
885 | { |
||
886 | $container = $this->getContainer('rpc-clients.yml'); |
||
887 | |||
888 | $this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
||
889 | $definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
||
890 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
891 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
||
892 | $this->assertEquals( |
||
893 | array( |
||
894 | array('initClient', array(true)), |
||
895 | array('setUnserializer', array('unserialize')), |
||
896 | array('setDirectReplyTo', array(false)), |
||
897 | ), |
||
898 | $definition->getMethodCalls() |
||
899 | ); |
||
900 | $this->assertTrue($definition->isLazy()); |
||
901 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
902 | } |
||
903 | |||
904 | public function testFooRpcServerDefinition() |
||
905 | { |
||
906 | $container = $this->getContainer('test.yml'); |
||
907 | |||
908 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
||
909 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
||
910 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
911 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
||
912 | $this->assertEquals(array( |
||
913 | array('initServer', array('foo_server')), |
||
914 | array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
||
915 | array('setSerializer', array('json_encode')), |
||
916 | ), |
||
917 | $definition->getMethodCalls() |
||
918 | ); |
||
919 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
920 | } |
||
921 | |||
922 | public function testDefaultRpcServerDefinition() |
||
923 | { |
||
924 | $container = $this->getContainer('test.yml'); |
||
925 | |||
926 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
||
927 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
||
928 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
929 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
||
930 | $this->assertEquals(array( |
||
931 | array('initServer', array('default_server')), |
||
932 | array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
||
933 | array('setSerializer', array('serialize')), |
||
934 | ), |
||
935 | $definition->getMethodCalls() |
||
936 | ); |
||
937 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
938 | } |
||
939 | |||
940 | public function testRpcServerWithQueueOptionsDefinition() |
||
941 | { |
||
942 | $container = $this->getContainer('test.yml'); |
||
943 | |||
944 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
||
945 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_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.server_with_queue_options'); |
||
948 | $this->assertEquals(array( |
||
949 | array('initServer', array('server_with_queue_options')), |
||
950 | array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
||
951 | array('setQueueOptions', array(array( |
||
952 | 'name' => 'server_with_queue_options-queue', |
||
953 | 'passive' => false, |
||
954 | 'durable' => true, |
||
955 | 'exclusive' => false, |
||
956 | 'auto_delete' => false, |
||
957 | 'nowait' => false, |
||
958 | 'arguments' => null, |
||
959 | 'ticket' => null, |
||
960 | 'routing_keys' => array(), |
||
961 | 'declare' => true, |
||
962 | ))), |
||
963 | array('setSerializer', array('serialize')), |
||
964 | ), |
||
965 | $definition->getMethodCalls() |
||
966 | ); |
||
967 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
968 | } |
||
969 | |||
970 | public function testRpcServerWithExchangeOptionsDefinition() |
||
971 | { |
||
972 | $container = $this->getContainer('test.yml'); |
||
973 | |||
974 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
||
975 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
||
976 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
977 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
||
978 | $this->assertEquals(array( |
||
979 | array('initServer', array('server_with_exchange_options')), |
||
980 | array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
||
981 | array('setExchangeOptions', array(array( |
||
982 | 'name' => 'exchange', |
||
983 | 'type' => 'topic', |
||
984 | 'passive' => false, |
||
985 | 'durable' => true, |
||
986 | 'auto_delete' => false, |
||
987 | 'internal' => null, |
||
988 | 'nowait' => false, |
||
989 | 'declare' => true, |
||
990 | 'arguments' => null, |
||
991 | 'ticket' => null, |
||
992 | ))), |
||
993 | array('setSerializer', array('serialize')), |
||
994 | ), |
||
995 | $definition->getMethodCalls() |
||
996 | ); |
||
997 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
998 | } |
||
999 | |||
1000 | public function testHasCollectorWhenChannelsExist() |
||
1001 | { |
||
1002 | $container = $this->getContainer('collector.yml'); |
||
1003 | |||
1004 | $this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
||
1005 | $definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
||
1006 | |||
1007 | $this->assertEquals(array( |
||
1008 | new Reference('old_sound_rabbit_mq.channel.default_producer'), |
||
1009 | new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
||
1010 | ), |
||
1011 | $definition->getArgument(0) |
||
1012 | ); |
||
1013 | } |
||
1014 | |||
1015 | public function testHasNoCollectorWhenNoChannelsExist() |
||
1016 | { |
||
1017 | $container = $this->getContainer('no_collector.yml'); |
||
1018 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
1019 | } |
||
1020 | |||
1021 | public function testCollectorCanBeDisabled() |
||
1025 | } |
||
1026 | |||
1027 | public function testExchangeArgumentsAreArray() |
||
1042 | } |
||
1043 | |||
1044 | public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
||
1045 | { |
||
1046 | $container = $this->getContainer('no_exchange_options.yml'); |
||
1047 | |||
1048 | $definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
||
1049 | $calls = $definition->getMethodCalls(); |
||
1050 | $this->assertEquals('setExchangeOptions', $calls[0][0]); |
||
1051 | $options = $calls[0][1]; |
||
1052 | |||
1053 | $this->assertEquals('', $options[0]['name']); |
||
1054 | $this->assertEquals('direct', $options[0]['type']); |
||
1055 | $this->assertEquals(false, $options[0]['declare']); |
||
1056 | $this->assertEquals(true, $options[0]['passive']); |
||
1057 | } |
||
1058 | |||
1059 | public function testProducersWithLogger() |
||
1060 | { |
||
1061 | $container = $this->getContainer('config_with_enable_logger.yml'); |
||
1062 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
1063 | $this->assertTrue( |
||
1064 | $definition->hasTag('monolog.logger'), 'service should be marked for logger' |
||
1065 | ); |
||
1066 | } |
||
1067 | |||
1068 | private function getContainer($file, $debug = false) |
||
1082 | } |
||
1083 | } |
||
1084 |