bug #26804 [Messenger] Fix handles tag attribute (ro0NL)

This PR was squashed before being merged into the 4.1-dev branch (closes #26804).

Discussion
----------

[Messenger] Fix handles tag attribute

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

92f7e37a27 [Messenger] Fix handles tag attribute
This commit is contained in:
Samuel ROZE 2018-04-04 20:34:11 +01:00
commit 08ca9f5a56
2 changed files with 9 additions and 2 deletions

View File

@ -69,7 +69,7 @@ class MessengerPass implements CompilerPassInterface
foreach ($container->findTaggedServiceIds($this->handlerTag, true) as $serviceId => $tags) {
foreach ($tags as $tag) {
$handles = $tag['handles'] ?? $this->guessHandledClasses($r = $container->getReflectionClass($container->getDefinition($serviceId)->getClass()), $serviceId);
$handles = isset($tag['handles']) ? array($tag['handles']) : $this->guessHandledClasses($r = $container->getReflectionClass($container->getDefinition($serviceId)->getClass()), $serviceId);
$priority = $tag['priority'] ?? 0;
foreach ($handles as $messageClass) {

View File

@ -33,6 +33,10 @@ class MessengerPassTest extends TestCase
->register(DummyHandler::class, DummyHandler::class)
->addTag('messenger.message_handler')
;
$container
->register(MissingArgumentTypeHandler::class, MissingArgumentTypeHandler::class)
->addTag('messenger.message_handler', array('handles' => SecondMessage::class))
;
$container
->register(DummyReceiver::class, DummyReceiver::class)
->addTag('messenger.receiver')
@ -43,7 +47,10 @@ class MessengerPassTest extends TestCase
$handlerLocatorDefinition = $container->getDefinition($container->getDefinition('messenger.handler_resolver')->getArgument(0));
$this->assertSame(ServiceLocator::class, $handlerLocatorDefinition->getClass());
$this->assertEquals(
array('handler.'.DummyMessage::class => new ServiceClosureArgument(new Reference(DummyHandler::class))),
array(
'handler.'.DummyMessage::class => new ServiceClosureArgument(new Reference(DummyHandler::class)),
'handler.'.SecondMessage::class => new ServiceClosureArgument(new Reference(MissingArgumentTypeHandler::class)),
),
$handlerLocatorDefinition->getArgument(0)
);