Total Complexity | 42 |
Total Lines | 978 |
Duplicated Lines | 0 % |
Changes | 19 | ||
Bugs | 0 | Features | 1 |
Complex classes like OldSoundRabbitMqExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OldSoundRabbitMqExtensionTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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() |
||
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' => 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) |
||
240 | { |
||
241 | $this->assertEquals(array( |
||
242 | array( |
||
243 | 'setArguments', |
||
244 | array( |
||
245 | $binding['arguments'] |
||
246 | ) |
||
247 | ), |
||
248 | array( |
||
249 | 'setDestination', |
||
250 | array( |
||
251 | $binding['destination'] |
||
252 | ) |
||
253 | ), |
||
254 | array( |
||
255 | 'setDestinationIsExchange', |
||
256 | array( |
||
257 | $binding['destination_is_exchange'] |
||
258 | ) |
||
259 | ), |
||
260 | array( |
||
261 | 'setExchange', |
||
262 | array( |
||
263 | $binding['exchange'] |
||
264 | ) |
||
265 | ), |
||
266 | array( |
||
267 | 'isNowait', |
||
268 | array( |
||
269 | $binding['nowait'] |
||
270 | ) |
||
271 | ), |
||
272 | array( |
||
273 | 'setRoutingKey', |
||
274 | array( |
||
275 | $binding['routing_key'] |
||
276 | ) |
||
277 | ), |
||
278 | ), |
||
279 | $definition->getMethodCalls() |
||
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 | ), |
||
318 | $definition->getMethodCalls() |
||
319 | ); |
||
320 | $this->assertEquals('My\Foo\Producer', $definition->getClass()); |
||
321 | } |
||
322 | |||
323 | public function testProducerArgumentAliases() |
||
324 | { |
||
325 | /** @var ContainerBuilder $container */ |
||
326 | $container = $this->getContainer('test.yml'); |
||
327 | |||
328 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
329 | // don't test if autowiring arguments functionality is not available |
||
330 | return; |
||
331 | } |
||
332 | |||
333 | // test expected aliases |
||
334 | $expectedAliases = array( |
||
335 | ProducerInterface::class . ' $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
336 | 'My\Foo\Producer $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
||
337 | ProducerInterface::class . ' $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
338 | 'My\Foo\Producer $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
||
339 | ProducerInterface::class . ' $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
340 | '%old_sound_rabbit_mq.producer.class% $defaultProducer' => 'old_sound_rabbit_mq.default_producer_producer', |
||
341 | ); |
||
342 | |||
343 | foreach($expectedAliases as $id => $target) { |
||
344 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
345 | |||
346 | $alias = $container->getAlias($id); |
||
347 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
348 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
349 | } |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @group alias |
||
354 | */ |
||
355 | public function testAliasedFooProducerDefinition() |
||
356 | { |
||
357 | $container = $this->getContainer('test.yml'); |
||
358 | |||
359 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_producer_producer')); |
||
360 | $this->assertTrue($container->has('foo_producer_alias')); |
||
361 | } |
||
362 | |||
363 | public function testDefaultProducerDefinition() |
||
364 | { |
||
365 | $container = $this->getContainer('test.yml'); |
||
366 | |||
367 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_producer_producer')); |
||
368 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_producer_producer'); |
||
369 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
370 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_producer'); |
||
371 | $this->assertEquals(array( |
||
372 | array( |
||
373 | 'setExchangeOptions', |
||
374 | array( |
||
375 | array( |
||
376 | 'name' => 'default_exchange', |
||
377 | 'type' => 'direct', |
||
378 | 'passive' => false, |
||
379 | 'durable' => true, |
||
380 | 'auto_delete' => false, |
||
381 | 'internal' => false, |
||
382 | 'nowait' => false, |
||
383 | 'arguments' => null, |
||
384 | 'ticket' => null, |
||
385 | 'declare' => true, |
||
386 | ) |
||
387 | ) |
||
388 | ), |
||
389 | array( |
||
390 | 'setQueueOptions', |
||
391 | array( |
||
392 | array( |
||
393 | 'name' => '', |
||
394 | 'declare' => false, |
||
395 | ) |
||
396 | ) |
||
397 | ) |
||
398 | ), |
||
399 | $definition->getMethodCalls() |
||
400 | ); |
||
401 | $this->assertEquals('%old_sound_rabbit_mq.producer.class%', $definition->getClass()); |
||
402 | } |
||
403 | |||
404 | public function testFooConsumerDefinition() |
||
405 | { |
||
406 | $container = $this->getContainer('test.yml'); |
||
407 | |||
408 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_consumer_consumer')); |
||
409 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_consumer_consumer'); |
||
410 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
411 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_consumer'); |
||
412 | $this->assertEquals(array( |
||
413 | array( |
||
414 | 'setExchangeOptions', |
||
415 | array( |
||
416 | array( |
||
417 | 'name' => 'foo_exchange', |
||
418 | 'type' => 'direct', |
||
419 | 'passive' => true, |
||
420 | 'durable' => false, |
||
421 | 'auto_delete' => true, |
||
422 | 'internal' => true, |
||
423 | 'nowait' => true, |
||
424 | 'arguments' => null, |
||
425 | 'ticket' => null, |
||
426 | 'declare' => true, |
||
427 | ) |
||
428 | ) |
||
429 | ), |
||
430 | array( |
||
431 | 'setQueueOptions', |
||
432 | array( |
||
433 | array( |
||
434 | 'name' => 'foo_queue', |
||
435 | 'passive' => true, |
||
436 | 'durable' => false, |
||
437 | 'exclusive' => true, |
||
438 | 'auto_delete' => true, |
||
439 | 'nowait' => true, |
||
440 | 'arguments' => null, |
||
441 | 'ticket' => null, |
||
442 | 'routing_keys' => array('android.#.upload', 'iphone.upload'), |
||
443 | 'declare' => true, |
||
444 | ) |
||
445 | ) |
||
446 | ), |
||
447 | array( |
||
448 | 'setCallback', |
||
449 | array(array(new Reference('foo.callback'), 'execute')) |
||
450 | ), |
||
451 | array( |
||
452 | 'setTimeoutWait', |
||
453 | array(3) |
||
454 | ) |
||
455 | ), |
||
456 | $definition->getMethodCalls() |
||
457 | ); |
||
458 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
459 | } |
||
460 | |||
461 | public function testConsumerArgumentAliases() |
||
462 | { |
||
463 | /** @var ContainerBuilder $container */ |
||
464 | $container = $this->getContainer('test.yml'); |
||
465 | |||
466 | if (!method_exists($container, 'registerAliasForArgument')) { |
||
467 | // don't test if autowiring arguments functionality is not available |
||
468 | return; |
||
469 | } |
||
470 | |||
471 | $expectedAliases = array( |
||
472 | ConsumerInterface::class . ' $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
473 | '%old_sound_rabbit_mq.consumer.class% $fooConsumer' => 'old_sound_rabbit_mq.foo_consumer_consumer', |
||
474 | ConsumerInterface::class . ' $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
475 | '%old_sound_rabbit_mq.consumer.class% $defaultConsumer' => 'old_sound_rabbit_mq.default_consumer_consumer', |
||
476 | ConsumerInterface::class . ' $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer', |
||
477 | '%old_sound_rabbit_mq.consumer.class% $qosTestConsumer' => 'old_sound_rabbit_mq.qos_test_consumer_consumer' |
||
478 | ); |
||
479 | foreach($expectedAliases as $id => $target) { |
||
480 | $this->assertTrue($container->hasAlias($id), sprintf('Container should have %s alias for autowiring support.', $id)); |
||
481 | |||
482 | $alias = $container->getAlias($id); |
||
483 | $this->assertEquals($target, (string)$alias, sprintf('Autowiring for %s should use %s.', $id, $target)); |
||
484 | $this->assertFalse($alias->isPublic(), sprintf('Autowiring alias for %s should be private', $id)); |
||
485 | } |
||
486 | } |
||
487 | |||
488 | public function testDefaultConsumerDefinition() |
||
489 | { |
||
490 | $container = $this->getContainer('test.yml'); |
||
491 | |||
492 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_consumer_consumer')); |
||
493 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
494 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
495 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_consumer'); |
||
496 | $this->assertEquals(array( |
||
497 | array( |
||
498 | 'setExchangeOptions', |
||
499 | array( |
||
500 | array( |
||
501 | 'name' => 'default_exchange', |
||
502 | 'type' => 'direct', |
||
503 | 'passive' => false, |
||
504 | 'durable' => true, |
||
505 | 'auto_delete' => false, |
||
506 | 'internal' => false, |
||
507 | 'nowait' => false, |
||
508 | 'arguments' => null, |
||
509 | 'ticket' => null, |
||
510 | 'declare' => true, |
||
511 | ) |
||
512 | ) |
||
513 | ), |
||
514 | array( |
||
515 | 'setQueueOptions', |
||
516 | array( |
||
517 | array( |
||
518 | 'name' => 'default_queue', |
||
519 | 'passive' => false, |
||
520 | 'durable' => true, |
||
521 | 'exclusive' => false, |
||
522 | 'auto_delete' => false, |
||
523 | 'nowait' => false, |
||
524 | 'arguments' => null, |
||
525 | 'ticket' => null, |
||
526 | 'routing_keys' => array(), |
||
527 | 'declare' => true, |
||
528 | ) |
||
529 | ) |
||
530 | ), |
||
531 | array( |
||
532 | 'setCallback', |
||
533 | array(array(new Reference('default.callback'), 'execute')) |
||
534 | ) |
||
535 | ), |
||
536 | $definition->getMethodCalls() |
||
537 | ); |
||
538 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass()); |
||
539 | } |
||
540 | |||
541 | public function testConsumerWithQosOptions() |
||
542 | { |
||
543 | $container = $this->getContainer('test.yml'); |
||
544 | |||
545 | $this->assertTrue($container->has('old_sound_rabbit_mq.qos_test_consumer_consumer')); |
||
546 | $definition = $container->getDefinition('old_sound_rabbit_mq.qos_test_consumer_consumer'); |
||
547 | $methodCalls = $definition->getMethodCalls(); |
||
548 | |||
549 | $setQosParameters = null; |
||
550 | foreach ($methodCalls as $methodCall) { |
||
551 | if ($methodCall[0] === 'setQosOptions') { |
||
552 | $setQosParameters = $methodCall[1]; |
||
553 | } |
||
554 | } |
||
555 | |||
556 | $this->assertIsArray($setQosParameters); |
||
557 | $this->assertEquals( |
||
558 | array( |
||
559 | 1024, |
||
560 | 1, |
||
561 | true |
||
562 | ), |
||
563 | $setQosParameters |
||
564 | ); |
||
565 | } |
||
566 | |||
567 | public function testMultipleConsumerDefinition() |
||
568 | { |
||
569 | $container = $this->getContainer('test.yml'); |
||
570 | |||
571 | $this->assertTrue($container->has('old_sound_rabbit_mq.multi_test_consumer_multiple')); |
||
572 | $definition = $container->getDefinition('old_sound_rabbit_mq.multi_test_consumer_multiple'); |
||
573 | $this->assertEquals(array( |
||
574 | array( |
||
575 | 'setExchangeOptions', |
||
576 | array( |
||
577 | array( |
||
578 | 'name' => 'foo_multiple_exchange', |
||
579 | 'type' => 'direct', |
||
580 | 'passive' => false, |
||
581 | 'durable' => true, |
||
582 | 'auto_delete' => false, |
||
583 | 'internal' => false, |
||
584 | 'nowait' => false, |
||
585 | 'arguments' => null, |
||
586 | 'ticket' => null, |
||
587 | 'declare' => true, |
||
588 | ) |
||
589 | ) |
||
590 | ), |
||
591 | array( |
||
592 | 'setQueues', |
||
593 | array( |
||
594 | array( |
||
595 | 'multi_test_1' => array( |
||
596 | 'name' => 'multi_test_1', |
||
597 | 'passive' => false, |
||
598 | 'durable' => true, |
||
599 | 'exclusive' => false, |
||
600 | 'auto_delete' => false, |
||
601 | 'nowait' => false, |
||
602 | 'arguments' => null, |
||
603 | 'ticket' => null, |
||
604 | 'routing_keys' => array(), |
||
605 | 'callback' => array(new Reference('foo.multiple_test1.callback'), 'execute'), |
||
606 | 'declare' => true, |
||
607 | ), |
||
608 | 'foo_bar_2' => array( |
||
609 | 'name' => 'foo_bar_2', |
||
610 | 'passive' => true, |
||
611 | 'durable' => false, |
||
612 | 'exclusive' => true, |
||
613 | 'auto_delete' => true, |
||
614 | 'nowait' => true, |
||
615 | 'arguments' => null, |
||
616 | 'ticket' => null, |
||
617 | 'routing_keys' => array( |
||
618 | 'android.upload', |
||
619 | 'iphone.upload' |
||
620 | ), |
||
621 | 'callback' => array(new Reference('foo.multiple_test2.callback'), 'execute'), |
||
622 | 'declare' => true, |
||
623 | ) |
||
624 | ) |
||
625 | ) |
||
626 | ), |
||
627 | array( |
||
628 | 'setQueuesProvider', |
||
629 | array( |
||
630 | new Reference('foo.queues_provider') |
||
631 | ) |
||
632 | ), |
||
633 | array( |
||
634 | 'setTimeoutWait', |
||
635 | array(3) |
||
636 | ) |
||
637 | ), |
||
638 | $definition->getMethodCalls() |
||
639 | ); |
||
640 | } |
||
641 | |||
642 | public function testDynamicConsumerDefinition() |
||
643 | { |
||
644 | $container = $this->getContainer('test.yml'); |
||
645 | |||
646 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_dyn_consumer_dynamic')); |
||
647 | $this->assertTrue($container->has('old_sound_rabbit_mq.bar_dyn_consumer_dynamic')); |
||
648 | |||
649 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_dyn_consumer_dynamic'); |
||
650 | $this->assertEquals(array( |
||
651 | array( |
||
652 | 'setExchangeOptions', |
||
653 | array( |
||
654 | array( |
||
655 | 'name' => 'foo_dynamic_exchange', |
||
656 | 'type' => 'direct', |
||
657 | 'passive' => false, |
||
658 | 'durable' => true, |
||
659 | 'auto_delete' => false, |
||
660 | 'internal' => false, |
||
661 | 'nowait' => false, |
||
662 | 'declare' => true, |
||
663 | 'arguments' => NULL, |
||
664 | 'ticket' => NULL, |
||
665 | ) |
||
666 | ) |
||
667 | ), |
||
668 | array( |
||
669 | 'setCallback', |
||
670 | array( |
||
671 | array(new Reference('foo.dynamic.callback'), 'execute') |
||
672 | ) |
||
673 | ), |
||
674 | array( |
||
675 | 'setQueueOptionsProvider', |
||
676 | array( |
||
677 | new Reference('foo.dynamic.provider') |
||
678 | ) |
||
679 | ) |
||
680 | ), |
||
681 | $definition->getMethodCalls() |
||
682 | ); |
||
683 | } |
||
684 | |||
685 | public function testFooAnonConsumerDefinition() |
||
686 | { |
||
687 | $container = $this->getContainer('test.yml'); |
||
688 | |||
689 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_anon_consumer_anon')); |
||
690 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_anon_consumer_anon'); |
||
691 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
692 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_anon_consumer'); |
||
693 | $this->assertEquals(array( |
||
694 | array( |
||
695 | 'setExchangeOptions', |
||
696 | array( |
||
697 | array( |
||
698 | 'name' => 'foo_anon_exchange', |
||
699 | 'type' => 'direct', |
||
700 | 'passive' => true, |
||
701 | 'durable' => false, |
||
702 | 'auto_delete' => true, |
||
703 | 'internal' => true, |
||
704 | 'nowait' => true, |
||
705 | 'arguments' => null, |
||
706 | 'ticket' => null, |
||
707 | 'declare' => true, |
||
708 | ) |
||
709 | ) |
||
710 | ), |
||
711 | array( |
||
712 | 'setCallback', |
||
713 | array(array(new Reference('foo_anon.callback'), 'execute')) |
||
714 | ) |
||
715 | ), |
||
716 | $definition->getMethodCalls() |
||
717 | ); |
||
718 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
719 | } |
||
720 | |||
721 | public function testDefaultAnonConsumerDefinition() |
||
722 | { |
||
723 | $container = $this->getContainer('test.yml'); |
||
724 | |||
725 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_anon_consumer_anon')); |
||
726 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_anon_consumer_anon'); |
||
727 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
728 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_anon_consumer'); |
||
729 | $this->assertEquals(array( |
||
730 | array( |
||
731 | 'setExchangeOptions', |
||
732 | array( |
||
733 | array( |
||
734 | 'name' => 'default_anon_exchange', |
||
735 | 'type' => 'direct', |
||
736 | 'passive' => false, |
||
737 | 'durable' => true, |
||
738 | 'auto_delete' => false, |
||
739 | 'internal' => false, |
||
740 | 'nowait' => false, |
||
741 | 'arguments' => null, |
||
742 | 'ticket' => null, |
||
743 | 'declare' => true, |
||
744 | ) |
||
745 | ) |
||
746 | ), |
||
747 | array( |
||
748 | 'setCallback', |
||
749 | array(array(new Reference('default_anon.callback'), 'execute')) |
||
750 | ) |
||
751 | ), |
||
752 | $definition->getMethodCalls() |
||
753 | ); |
||
754 | $this->assertEquals('%old_sound_rabbit_mq.anon_consumer.class%', $definition->getClass()); |
||
755 | } |
||
756 | |||
757 | public function testFooRpcClientDefinition() |
||
758 | { |
||
759 | $container = $this->getContainer('rpc-clients.yml'); |
||
760 | |||
761 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_client_rpc')); |
||
762 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_client_rpc'); |
||
763 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
764 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_client'); |
||
765 | $this->assertEquals( |
||
766 | array( |
||
767 | array('initClient', array(true)), |
||
768 | array('setUnserializer', array('json_decode')), |
||
769 | array('setDirectReplyTo', array(true)), |
||
770 | ), |
||
771 | $definition->getMethodCalls() |
||
772 | ); |
||
773 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
774 | } |
||
775 | |||
776 | public function testDefaultRpcClientDefinition() |
||
794 | } |
||
795 | |||
796 | public function testLazyRpcClientDefinition() |
||
797 | { |
||
798 | $container = $this->getContainer('rpc-clients.yml'); |
||
799 | |||
800 | $this->assertTrue($container->has('old_sound_rabbit_mq.lazy_client_rpc')); |
||
801 | $definition = $container->getDefinition('old_sound_rabbit_mq.lazy_client_rpc'); |
||
802 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
803 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.lazy_client'); |
||
804 | $this->assertEquals( |
||
805 | array( |
||
806 | array('initClient', array(true)), |
||
807 | array('setUnserializer', array('unserialize')), |
||
808 | array('setDirectReplyTo', array(false)), |
||
809 | ), |
||
810 | $definition->getMethodCalls() |
||
811 | ); |
||
812 | $this->assertTrue($definition->isLazy()); |
||
813 | $this->assertEquals('%old_sound_rabbit_mq.rpc_client.class%', $definition->getClass()); |
||
814 | } |
||
815 | |||
816 | public function testFooRpcServerDefinition() |
||
817 | { |
||
818 | $container = $this->getContainer('test.yml'); |
||
819 | |||
820 | $this->assertTrue($container->has('old_sound_rabbit_mq.foo_server_server')); |
||
821 | $definition = $container->getDefinition('old_sound_rabbit_mq.foo_server_server'); |
||
822 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.foo_connection'); |
||
823 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.foo_server'); |
||
824 | $this->assertEquals(array( |
||
825 | array('initServer', array('foo_server')), |
||
826 | array('setCallback', array(array(new Reference('foo_server.callback'), 'execute'))), |
||
827 | array('setSerializer', array('json_encode')), |
||
828 | ), |
||
829 | $definition->getMethodCalls() |
||
830 | ); |
||
831 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
832 | } |
||
833 | |||
834 | public function testDefaultRpcServerDefinition() |
||
835 | { |
||
836 | $container = $this->getContainer('test.yml'); |
||
837 | |||
838 | $this->assertTrue($container->has('old_sound_rabbit_mq.default_server_server')); |
||
839 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_server_server'); |
||
840 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
841 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.default_server'); |
||
842 | $this->assertEquals(array( |
||
843 | array('initServer', array('default_server')), |
||
844 | array('setCallback', array(array(new Reference('default_server.callback'), 'execute'))), |
||
845 | array('setSerializer', array('serialize')), |
||
846 | ), |
||
847 | $definition->getMethodCalls() |
||
848 | ); |
||
849 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
850 | } |
||
851 | |||
852 | public function testRpcServerWithQueueOptionsDefinition() |
||
853 | { |
||
854 | $container = $this->getContainer('test.yml'); |
||
855 | |||
856 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server')); |
||
857 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server'); |
||
858 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
859 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options'); |
||
860 | $this->assertEquals(array( |
||
861 | array('initServer', array('server_with_queue_options')), |
||
862 | array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))), |
||
863 | array('setQueueOptions', array(array( |
||
864 | 'name' => 'server_with_queue_options-queue', |
||
865 | 'passive' => false, |
||
866 | 'durable' => true, |
||
867 | 'exclusive' => false, |
||
868 | 'auto_delete' => false, |
||
869 | 'nowait' => false, |
||
870 | 'arguments' => null, |
||
871 | 'ticket' => null, |
||
872 | 'routing_keys' => array(), |
||
873 | 'declare' => true, |
||
874 | ))), |
||
875 | array('setSerializer', array('serialize')), |
||
876 | ), |
||
877 | $definition->getMethodCalls() |
||
878 | ); |
||
879 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
880 | } |
||
881 | |||
882 | public function testRpcServerWithExchangeOptionsDefinition() |
||
883 | { |
||
884 | $container = $this->getContainer('test.yml'); |
||
885 | |||
886 | $this->assertTrue($container->has('old_sound_rabbit_mq.server_with_exchange_options_server')); |
||
887 | $definition = $container->getDefinition('old_sound_rabbit_mq.server_with_exchange_options_server'); |
||
888 | $this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default'); |
||
889 | $this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_exchange_options'); |
||
890 | $this->assertEquals(array( |
||
891 | array('initServer', array('server_with_exchange_options')), |
||
892 | array('setCallback', array(array(new Reference('server_with_exchange_options.callback'), 'execute'))), |
||
893 | array('setExchangeOptions', array(array( |
||
894 | 'name' => 'exchange', |
||
895 | 'type' => 'topic', |
||
896 | 'passive' => false, |
||
897 | 'durable' => true, |
||
898 | 'auto_delete' => false, |
||
899 | 'internal' => null, |
||
900 | 'nowait' => false, |
||
901 | 'declare' => true, |
||
902 | 'arguments' => null, |
||
903 | 'ticket' => null, |
||
904 | ))), |
||
905 | array('setSerializer', array('serialize')), |
||
906 | ), |
||
907 | $definition->getMethodCalls() |
||
908 | ); |
||
909 | $this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass()); |
||
910 | } |
||
911 | |||
912 | public function testHasCollectorWhenChannelsExist() |
||
913 | { |
||
914 | $container = $this->getContainer('collector.yml'); |
||
915 | |||
916 | $this->assertTrue($container->has('old_sound_rabbit_mq.data_collector')); |
||
917 | $definition = $container->getDefinition('old_sound_rabbit_mq.data_collector'); |
||
918 | |||
919 | $this->assertEquals(array( |
||
920 | new Reference('old_sound_rabbit_mq.channel.default_producer'), |
||
921 | new Reference('old_sound_rabbit_mq.channel.default_consumer'), |
||
922 | ), |
||
923 | $definition->getArgument(0) |
||
924 | ); |
||
925 | } |
||
926 | |||
927 | public function testHasNoCollectorWhenNoChannelsExist() |
||
928 | { |
||
929 | $container = $this->getContainer('no_collector.yml'); |
||
930 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
931 | } |
||
932 | |||
933 | public function testCollectorCanBeDisabled() |
||
934 | { |
||
935 | $container = $this->getContainer('collector_disabled.yml'); |
||
936 | $this->assertFalse($container->has('old_sound_rabbit_mq.data_collector')); |
||
937 | } |
||
938 | |||
939 | public function testExchangeArgumentsAreArray() |
||
954 | } |
||
955 | |||
956 | public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault() |
||
957 | { |
||
958 | $container = $this->getContainer('no_exchange_options.yml'); |
||
959 | |||
960 | $definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer'); |
||
961 | $calls = $definition->getMethodCalls(); |
||
962 | $this->assertEquals('setExchangeOptions', $calls[0][0]); |
||
963 | $options = $calls[0][1]; |
||
964 | |||
965 | $this->assertEquals('', $options[0]['name']); |
||
966 | $this->assertEquals('direct', $options[0]['type']); |
||
967 | $this->assertEquals(false, $options[0]['declare']); |
||
968 | $this->assertEquals(true, $options[0]['passive']); |
||
969 | } |
||
970 | |||
971 | public function testProducersWithLogger() |
||
972 | { |
||
973 | $container = $this->getContainer('config_with_enable_logger.yml'); |
||
974 | $definition = $container->getDefinition('old_sound_rabbit_mq.default_consumer_consumer'); |
||
975 | $this->assertTrue( |
||
976 | $definition->hasTag('monolog.logger'), 'service should be marked for logger' |
||
977 | ); |
||
978 | } |
||
979 | |||
980 | private function getContainer($file, $debug = false) |
||
994 | } |
||
995 | } |
||
996 |