|
16 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
17 | 17 | use Symfony\Component\DependencyInjection\Reference;
|
18 | 18 | use Symfony\Component\DependencyInjection\ServiceLocator;
|
| 19 | +use Symfony\Component\Messenger\Adapter\AmqpExt\AmqpReceiver; |
| 20 | +use Symfony\Component\Messenger\Adapter\AmqpExt\AmqpSender; |
19 | 21 | use Symfony\Component\Messenger\ContainerHandlerLocator;
|
20 | 22 | use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
|
21 | 23 | use Symfony\Component\Messenger\Handler\ChainHandler;
|
@@ -90,6 +92,26 @@ public function testGetClassesFromTheHandlerSubscriberInterface()
|
90 | 92 | $this->assertEquals(array(new Reference(PrioritizedHandler::class), new Reference(HandlerWithMultipleMessages::class)), $definition->getArgument(0));
|
91 | 93 | }
|
92 | 94 |
|
| 95 | + public function testItRegistersReceivers() |
| 96 | + { |
| 97 | + $container = $this->getContainerBuilder(); |
| 98 | + $container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver', array('name' => 'amqp')); |
| 99 | + |
| 100 | + (new MessengerPass())->process($container); |
| 101 | + |
| 102 | + $this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0)); |
| 103 | + } |
| 104 | + |
| 105 | + public function testItRegistersSenders() |
| 106 | + { |
| 107 | + $container = $this->getContainerBuilder(); |
| 108 | + $container->register(AmqpSender::class, AmqpSender::class)->addTag('messenger.sender', array('name' => 'amqp')); |
| 109 | + |
| 110 | + (new MessengerPass())->process($container); |
| 111 | + |
| 112 | + $this->assertEquals(array('amqp' => new Reference(AmqpSender::class), AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0)); |
| 113 | + } |
| 114 | + |
93 | 115 | /**
|
94 | 116 | * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
95 | 117 | * @expectedExceptionMessage Invalid handler service "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler": message class "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessage" used as argument type in method "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler::__invoke()" does not exist.
|
@@ -201,6 +223,11 @@ private function getContainerBuilder(): ContainerBuilder
|
201 | 223 | $container->setParameter('kernel.debug', true);
|
202 | 224 | $container->register('message_bus', ContainerHandlerLocator::class);
|
203 | 225 |
|
| 226 | + $container |
| 227 | + ->register('messenger.sender_locator', ServiceLocator::class) |
| 228 | + ->addArgument(new Reference('service_container')) |
| 229 | + ; |
| 230 | + |
204 | 231 | $container
|
205 | 232 | ->register('messenger.handler_resolver', ContainerHandlerLocator::class)
|
206 | 233 | ->addArgument(new Reference('service_container'))
|
|
0 commit comments