|
3 | 3 | namespace OldSound\RabbitMqBundle\Tests\DependencyInjection;
|
4 | 4 |
|
5 | 5 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 6 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
6 | 7 | use Symfony\Component\DependencyInjection\Definition;
|
7 | 8 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
8 | 9 | use Symfony\Component\Config\FileLocator;
|
@@ -318,6 +319,36 @@ public function testFooProducerDefinition()
|
318 | 319 | $this->assertEquals('My\Foo\Producer', $definition->getClass());
|
319 | 320 | }
|
320 | 321 |
|
| 322 | + public function testProducerArgumentAliases() |
| 323 | + { |
| 324 | + /** @var ContainerInterface $container */ |
| 325 | + $container = $this->getContainer('test.yml'); |
| 326 | + |
| 327 | + if (!method_exists($container, 'registerAliasForArgument')) { |
| 328 | + // don't test if autowiring arguments functionality is not available |
| 329 | + return; |
| 330 | + } |
| 331 | + |
| 332 | + // test expected aliases |
| 333 | + $producerInterface = 'OldSound\RabbitMqBundle\RabbitMq\ProducerInterface'; |
| 334 | + $expectedAliases = array( |
| 335 | + $producerInterface . ' $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
| 336 | + 'My\Foo\Producer $fooProducer' => 'old_sound_rabbit_mq.foo_producer_producer', |
| 337 | + $producerInterface . ' $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
| 338 | + 'My\Foo\Producer $fooProducerAliasedProducer' => 'old_sound_rabbit_mq.foo_producer_aliased_producer', |
| 339 | + $producerInterface . ' $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 | + |
321 | 352 | /**
|
322 | 353 | * @group alias
|
323 | 354 | */
|
@@ -427,6 +458,33 @@ public function testFooConsumerDefinition()
|
427 | 458 | $this->assertEquals('%old_sound_rabbit_mq.consumer.class%', $definition->getClass());
|
428 | 459 | }
|
429 | 460 |
|
| 461 | + public function testConsumerArgumentAliases() |
| 462 | + { |
| 463 | + $container = $this->getContainer('test.yml'); |
| 464 | + |
| 465 | + if (!method_exists($container, 'registerAliasForArgument')) { |
| 466 | + // don't test if autowiring arguments functionality is not available |
| 467 | + return; |
| 468 | + } |
| 469 | + |
| 470 | + $consumerInterface = 'OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface'; |
| 471 | + $expectedAliases = array( |
| 472 | + $consumerInterface . ' $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 . ' $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 . ' $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 | + |
430 | 488 | public function testDefaultConsumerDefinition()
|
431 | 489 | {
|
432 | 490 | $container = $this->getContainer('test.yml');
|
|
0 commit comments