Total Complexity | 42 |
Total Lines | 1017 |
Duplicated Lines | 0 % |
Changes | 19 | ||
Bugs | 0 | 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(['old_sound_rabbit_mq.connection_factory.foo_connection', 'createConnection'], $definition->getFactory()); |
||
27 | $this->assertEquals([ |
||
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' => [], |
||
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(['old_sound_rabbit_mq.connection_factory.ssl_connection', 'createConnection'], $definition->getFactory()); |
||
55 | $this->assertEquals([ |
||
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' => [ |
||
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(['old_sound_rabbit_mq.connection_factory.lazy_connection', 'createConnection'], $definition->getFactory()); |
||
85 | $this->assertEquals([ |
||
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' => [], |
||
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(['old_sound_rabbit_mq.connection_factory.default', 'createConnection'], $definition->getFactory()); |
||
113 | $this->assertEquals([ |
||
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' => [], |
||
123 | 'keepalive' => false, |
||
124 | 'heartbeat' => 0, |
||
125 | 'use_socket' => false, |
||
126 | 'url' => '', |
||
127 | 'hosts' => [], |
||
128 | ], $factory->getArgument(1)); |
||
129 | $this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass()); |
||
130 | } |
||
131 | |||
132 | public function testSocketConnectionDefinition() |
||
133 | { |
||
134 | $container = $this->getContainer('test.yml'); |
||
135 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.socket_connection')); |
||
136 | $definiton = $container->getDefinition('old_sound_rabbit_mq.connection.socket_connection'); |
||
137 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.socket_connection')); |
||
138 | $this->assertEquals('%old_sound_rabbit_mq.socket_connection.class%', $definiton->getClass()); |
||
139 | } |
||
140 | |||
141 | public function testLazySocketConnectionDefinition() |
||
142 | { |
||
143 | $container = $this->getContainer('test.yml'); |
||
144 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_socket')); |
||
145 | $definiton = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_socket'); |
||
146 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_socket')); |
||
147 | $this->assertEquals('%old_sound_rabbit_mq.lazy.socket_connection.class%', $definiton->getClass()); |
||
148 | } |
||
149 | |||
150 | public function testClusterConnectionDefinition() |
||
151 | { |
||
152 | $container = $this->getContainer('test.yml'); |
||
153 | |||
154 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection.cluster_connection')); |
||
155 | $definition = $container->getDefinition('old_sound_rabbit_mq.connection.cluster_connection'); |
||
156 | $this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.cluster_connection')); |
||
157 | $factory = $container->getDefinition('old_sound_rabbit_mq.connection_factory.cluster_connection'); |
||
158 | $this->assertEquals(['old_sound_rabbit_mq.connection_factory.cluster_connection', 'createConnection'], $definition->getFactory()); |
||
159 | $this->assertEquals([ |
||
160 | 'hosts' => [ |
||
161 | [ |
||
162 | 'host' => 'cluster_host', |
||
163 | 'port' => 111, |
||
164 | 'user' => 'cluster_user', |
||
165 | 'password' => 'cluster_password', |
||
166 | 'vhost' => '/cluster', |
||
167 | 'url' => '', |
||
168 | ], |
||
169 | [ |
||
170 | 'host' => 'localhost', |
||
171 | 'port' => 5672, |
||
172 | 'user' => 'guest', |
||
173 | 'password' => 'guest', |
||
174 | 'vhost' => '/', |
||
175 | 'url' => 'amqp://cluster_url_host:cluster_url_pass@host:10000/cluster_url_vhost', |
||
176 | ], |
||
177 | ], |
||
178 | 'host' => 'localhost', |
||
179 | 'port' => 5672, |
||
180 | 'user' => 'guest', |
||
181 | 'password' => 'guest', |
||
182 | 'vhost' => '/', |
||
183 | 'lazy' => false, |
||
184 | 'connection_timeout' => 3, |
||
185 | 'read_write_timeout' => 3, |
||
186 | 'ssl_context' => [], |
||
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 = [ |
||
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 = [ |
||
221 | 'arguments' => ['moo' => 'cow'], |
||
222 | 'class' => '%old_sound_rabbit_mq.binding.class%', |
||
223 | 'connection' => 'default2', |
||
224 | 'exchange' => 'moo', |
||
225 | 'destination' => 'cow', |
||
226 | 'destination_is_exchange' => true, |
||
227 | 'nowait' => true, |
||
228 | 'routing_key' => null, |
||
229 | ]; |
||
230 | ksort($binding); |
||
231 | $key = md5(json_encode($binding)); |
||
232 | $name = sprintf('old_sound_rabbit_mq.binding.%s', $key); |
||
233 | $this->assertTrue($container->has($name)); |
||
234 | $definition = $container->getDefinition($name); |
||
235 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default2'); |
||
236 | $this->assertBindingMethodCalls($definition, $binding); |
||
237 | } |
||
238 | |||
239 | protected function assertBindingMethodCalls(Definition $definition, $binding) |
||
240 | { |
||
241 | $this->assertEquals( |
||
242 | [ |
||
243 | [ |
||
244 | 'setArguments', |
||
245 | [ |
||
246 | $binding['arguments'], |
||
247 | ], |
||
248 | ], |
||
249 | [ |
||
250 | 'setDestination', |
||
251 | [ |
||
252 | $binding['destination'], |
||
253 | ], |
||
254 | ], |
||
255 | [ |
||
256 | 'setDestinationIsExchange', |
||
257 | [ |
||
258 | $binding['destination_is_exchange'], |
||
259 | ], |
||
260 | ], |
||
261 | [ |
||
262 | 'setExchange', |
||
263 | [ |
||
264 | $binding['exchange'], |
||
265 | ], |
||
266 | ], |
||
267 | [ |
||
268 | 'isNowait', |
||
269 | [ |
||
270 | $binding['nowait'], |
||
271 | ], |
||
272 | ], |
||
273 | [ |
||
274 | 'setRoutingKey', |
||
275 | [ |
||
276 | $binding['routing_key'], |
||
277 | ], |
||
278 | ], |
||
279 | ], |
||
280 | $definition->getMethodCalls() |
||
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 | [ |
||
293 | [ |
||
294 | 'setExchangeOptions', |
||
295 | [ |
||
296 | [ |
||
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 | [ |
||
311 | 'setQueueOptions', |
||
312 | [ |
||
313 | [ |
||
314 | 'name' => '', |
||
315 | 'declare' => false, |
||
316 | ) |
||
|
|||
317 | ) |
||
318 | ), |
||
319 | array( |
||
320 | 'setConfirmationTimeout', |
||
321 | array( |
||
322 | 0 |
||
323 | ) |
||
324 | ), |
||
325 | array( |
||
326 | 'setDefaultRoutingKey', |
||
327 | [''], |
||
328 | ], |
||
329 | [ |
||
330 | 'setContentType', |
||
331 | ['text/plain'], |
||
332 | ], |
||
333 | [ |
||
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 = [ |
||
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 | [ |
||
394 | [ |
||
395 | 'setExchangeOptions', |
||
396 | [ |
||
397 | [ |
||
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 | [ |
||
412 | 'setQueueOptions', |
||
413 | [ |
||
414 | [ |
||
415 | 'name' => '', |
||
416 | 'declare' => false, |
||
417 | ) |
||
418 | ) |
||
419 | ), |
||
420 | array( |
||
421 | 'setConfirmationTimeout', |
||
422 | array( |
||
423 | 0 |
||
424 | ) |
||
425 | ), |
||
426 | array( |
||
427 | 'setDefaultRoutingKey', |
||
428 | [''], |
||
429 | ], |
||
430 | [ |
||
431 | 'setContentType', |
||
432 | ['text/plain'], |
||
433 | ], |
||
434 | [ |
||
435 | 'setDeliveryMode', |
||
436 | [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 | [ |
||
513 | [ |
||
514 | 'setExchangeOptions', |
||
515 | [ |
||
516 | [ |
||
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 | [ |
||
531 | 'setQueueOptions', |
||
532 | [ |
||
533 | [ |
||
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' => ['android.#.upload', 'iphone.upload'], |
||
543 | 'declare' => true, |
||
544 | ], |
||
545 | ], |
||
546 | ], |
||
547 | [ |
||
548 | 'setCallback', |
||
549 | [[new Reference('foo.callback'), 'execute']], |
||
550 | ], |
||
551 | [ |
||
552 | 'setTimeoutWait', |
||
553 | [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 = [ |
||
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 | [ |
||
598 | [ |
||
599 | 'setExchangeOptions', |
||
600 | [ |
||
601 | [ |
||
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 | [ |
||
616 | 'setQueueOptions', |
||
617 | [ |
||
618 | [ |
||
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' => [], |
||
628 | 'declare' => true, |
||
629 | ], |
||
630 | ], |
||
631 | ], |
||
632 | [ |
||
633 | 'setCallback', |
||
634 | [[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 | [ |
||
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 | [ |
||
676 | [ |
||
677 | 'setExchangeOptions', |
||
678 | [ |
||
679 | [ |
||
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 | [ |
||
694 | 'setQueues', |
||
695 | [ |
||
696 | [ |
||
697 | 'multi_test_1' => [ |
||
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' => [], |
||
707 | 'callback' => [new Reference('foo.multiple_test1.callback'), 'execute'], |
||
708 | 'declare' => true, |
||
709 | ], |
||
710 | 'foo_bar_2' => [ |
||
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' => [ |
||
720 | 'android.upload', |
||
721 | 'iphone.upload', |
||
722 | ], |
||
723 | 'callback' => [new Reference('foo.multiple_test2.callback'), 'execute'], |
||
724 | 'declare' => true, |
||
725 | ], |
||
726 | ], |
||
727 | ], |
||
728 | ], |
||
729 | [ |
||
730 | 'setQueuesProvider', |
||
731 | [ |
||
732 | new Reference('foo.queues_provider'), |
||
733 | ], |
||
734 | ], |
||
735 | [ |
||
736 | 'setTimeoutWait', |
||
737 | [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 | [ |
||
754 | [ |
||
755 | 'setExchangeOptions', |
||
756 | [ |
||
757 | [ |
||
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 | [ |
||
772 | 'setCallback', |
||
773 | [ |
||
774 | [new Reference('foo.dynamic.callback'), 'execute'], |
||
775 | ], |
||
776 | ], |
||
777 | [ |
||
778 | 'setQueueOptionsProvider', |
||
779 | [ |
||
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 | [ |
||
798 | [ |
||
799 | 'setExchangeOptions', |
||
800 | [ |
||
801 | [ |
||
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 | [ |
||
816 | 'setCallback', |
||
817 | [[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 | [ |
||
835 | [ |
||
836 | 'setExchangeOptions', |
||
837 | [ |
||
838 | [ |
||
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 | [ |
||
853 | 'setCallback', |
||
854 | [[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 | [ |
||
872 | ['initClient', [true]], |
||
873 | ['setUnserializer', ['json_decode']], |
||
874 | ['setDirectReplyTo', [true]], |
||
875 | ], |
||
876 | $definition->getMethodCalls() |
||
877 | ); |
||
878 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
879 | } |
||
880 | |||
881 | public function testDefaultRpcClientDefinition() |
||
882 | { |
||
883 | $container = $this->getContainer('rpc-clients.yml'); |
||
884 | |||
885 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_client_rpc')); |
||
886 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_client_rpc'); |
||
887 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
888 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_client'); |
||
889 | $this->assertEquals( |
||
890 | [ |
||
891 | ['initClient', [true]], |
||
892 | ['setUnserializer', ['unserialize']], |
||
893 | ['setDirectReplyTo', [false]], |
||
894 | ], |
||
895 | $definition->getMethodCalls() |
||
896 | ); |
||
897 | $this->assertFalse($definition->isLazy()); |
||
898 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
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 | [ |
||
911 | ['initClient', [true]], |
||
912 | ['setUnserializer', ['unserialize']], |
||
913 | ['setDirectReplyTo', [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 | [ |
||
931 | ['initServer', ['foo_server']], |
||
932 | ['setCallback', [[new Reference('foo_server.callback'), 'execute']]], |
||
933 | ['setSerializer', ['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 | [ |
||
950 | ['initServer', ['default_server']], |
||
951 | ['setCallback', [[new Reference('default_server.callback'), 'execute']]], |
||
952 | ['setSerializer', ['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 | [ |
||
969 | ['initServer', ['server_with_queue_options']], |
||
970 | ['setCallback', [[new Reference('server_with_queue_options.callback'), 'execute']]], |
||
971 | ['setQueueOptions', [[ |
||
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' => [], |
||
981 | 'declare' => true, |
||
982 | ]]], |
||
983 | ['setSerializer', ['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 | [ |
||
1000 | ['initServer', ['server_with_exchange_options']], |
||
1001 | ['setCallback', [[new Reference('server_with_exchange_options.callback'), 'execute']]], |
||
1002 | ['setExchangeOptions', [[ |
||
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 | ['setSerializer', ['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 | [ |
||
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) |
||
1107 |