[Messenger] Added support for from_transport attribute on messenger.message_handler tag

This commit is contained in:
Ruud Kamphuis 2019-08-24 11:05:28 +02:00 committed by Fabien Potencier
parent dc8d470752
commit c965e4e844
3 changed files with 24 additions and 0 deletions

View File

@ -9,6 +9,7 @@ CHANGELOG
* Added support for auto trimming of Redis streams.
* `InMemoryTransport` handle acknowledged and rejected messages.
* Made all dispatched worker event classes final.
* Added support for `from_transport` attribute on `messenger.message_handler` tag.
4.3.0
-----

View File

@ -109,6 +109,10 @@ class MessengerPass implements CompilerPassInterface
$options = ['method' => $options];
}
if (!isset($options['from_transport']) && isset($tag['from_transport'])) {
$options['from_transport'] = $tag['from_transport'];
}
$priority = $tag['priority'] ?? $options['priority'] ?? 0;
$method = $options['method'] ?? '__invoke';

View File

@ -78,6 +78,25 @@ class MessengerPassTest extends TestCase
);
}
public function testFromTransportViaTagAttribute()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
$container
->register(DummyHandler::class, DummyHandler::class)
->addTag('messenger.message_handler', ['from_transport' => 'async'])
;
(new MessengerPass())->process($container);
$handlersLocatorDefinition = $container->getDefinition($busId.'.messenger.handlers_locator');
$this->assertSame(HandlersLocator::class, $handlersLocatorDefinition->getClass());
$handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
$this->assertCount(1, $handlerDescriptionMapping);
$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [DummyHandler::class], [['from_transport' => 'async']]);
}
public function testProcessHandlersByBus()
{
$container = $this->getContainerBuilder($commandBusId = 'command_bus');