|
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;
|
@@ -88,6 +90,26 @@ public function testGetClassesFromTheHandlerSubscriberInterface()
|
88 | 90 | $this->assertEquals(array(new Reference(PrioritizedHandler::class), new Reference(HandlerWithMultipleMessages::class)), $definition->getArgument(0));
|
89 | 91 | }
|
90 | 92 |
|
| 93 | + public function testItRegistersReceivers() |
| 94 | + { |
| 95 | + $container = $this->getContainerBuilder(); |
| 96 | + $container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver', array('name' => 'amqp')); |
| 97 | + |
| 98 | + (new MessengerPass())->process($container); |
| 99 | + |
| 100 | + $this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0)); |
| 101 | + } |
| 102 | + |
| 103 | + public function testItRegistersSenders() |
| 104 | + { |
| 105 | + $container = $this->getContainerBuilder(); |
| 106 | + $container->register(AmqpSender::class, AmqpSender::class)->addTag('messenger.sender', array('name' => 'amqp')); |
| 107 | + |
| 108 | + (new MessengerPass())->process($container); |
| 109 | + |
| 110 | + $this->assertEquals(array('amqp' => new Reference(AmqpSender::class), AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0)); |
| 111 | + } |
| 112 | + |
91 | 113 | /**
|
92 | 114 | * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
93 | 115 | * @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.
|
@@ -199,6 +221,11 @@ private function getContainerBuilder(): ContainerBuilder
|
199 | 221 | $container->setParameter('kernel.debug', true);
|
200 | 222 | $container->register('message_bus', ContainerHandlerLocator::class);
|
201 | 223 |
|
| 224 | + $container |
| 225 | + ->register('messenger.sender_locator', ServiceLocator::class) |
| 226 | + ->addArgument(new Reference('service_container')) |
| 227 | + ; |
| 228 | + |
202 | 229 | $container
|
203 | 230 | ->register('messenger.handler_resolver', ContainerHandlerLocator::class)
|
204 | 231 | ->addArgument(new Reference('service_container'))
|
|
0 commit comments