|
2 | 2 |
|
3 | 3 | namespace OldSound\RabbitMqBundle\Tests\DependencyInjection;
|
4 | 4 |
|
| 5 | +use OldSound\RabbitMqBundle\DependencyInjection\OldSoundRabbitMqExtension; |
| 6 | +use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface; |
| 7 | +use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Symfony\Component\Config\FileLocator; |
5 | 10 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
6 | 11 | use Symfony\Component\DependencyInjection\Definition;
|
7 |
| -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
8 |
| -use Symfony\Component\Config\FileLocator; |
9 | 12 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
10 |
| -use OldSound\RabbitMqBundle\DependencyInjection\OldSoundRabbitMqExtension; |
| 13 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
11 | 14 | use Symfony\Component\DependencyInjection\Reference;
|
12 |
| -use PHPUnit\Framework\TestCase; |
13 | 15 |
|
14 | 16 | class OldSoundRabbitMqExtensionTest extends TestCase
|
15 | 17 | {
|
@@ -318,6 +320,35 @@ public function testFooProducerDefinition()
|
318 | 320 | $this->assertEquals('My\Foo\Producer', $definition->getClass());
|
319 | 321 | }
|
320 | 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 | + |
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 | + /** @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 | + |
430 | 488 | public function testDefaultConsumerDefinition()
|
431 | 489 | {
|
432 | 490 | $container = $this->getContainer('test.yml');
|
|
0 commit comments