Permalink
Browse files

bug #27820 [Messenger] Fix a bug when having more than one named hand…

…ler per message subscriber (sroze)

This PR was merged into the 4.1 branch.

Discussion
----------

[Messenger] Fix a bug when having more than one named handler per message subscriber

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ø
| License       | MIT
| Doc PR        | ø

It turns out that when using multiple named handler on the same subscriber class, it wasn't working properly at all. It fixes it and obviously add a test for it :)

Commits
-------

47d715e Fix a bug when having more than one named handler per message subscriber
  • Loading branch information...
nicolas-grekas committed Jul 4, 2018
2 parents 0fbcfbd + 47d715e commit 44d43303a9ec89476dce722308294e1a4c8126e0
@@ -128,11 +128,13 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
if ('__invoke' !== $method) {
$wrapperDefinition = (new Definition('callable'))->addArgument(array(new Reference($serviceId), $method))->setFactory('Closure::fromCallable');
$definitions[$serviceId = '.messenger.method_on_object_wrapper.'.ContainerBuilder::hash($messageClass.':'.$messagePriority.':'.$serviceId.':'.$method)] = $wrapperDefinition;
$definitions[$definitionId = '.messenger.method_on_object_wrapper.'.ContainerBuilder::hash($messageClass.':'.$messagePriority.':'.$serviceId.':'.$method)] = $wrapperDefinition;
} else {
$definitionId = $serviceId;
}
foreach ($handlerBuses as $handlerBus) {
$handlersByBusAndMessage[$handlerBus][$messageClass][$messagePriority][] = $serviceId;
$handlersByBusAndMessage[$handlerBus][$messageClass][$messagePriority][] = $definitionId;
}
}
}
@@ -288,7 +288,12 @@ public function testItShouldNotThrowIfGeneratorIsReturnedInsteadOfArray()
$handlerMapping = $handlerLocatorDefinition->getArgument(0);
$this->assertArrayHasKey('handler.'.DummyMessage::class, $handlerMapping);
$firstReference = $handlerMapping['handler.'.DummyMessage::class]->getValues()[0];
$this->assertEquals(array(new Reference(HandlerWithGenerators::class), 'dummyMethod'), $container->getDefinition($firstReference)->getArgument(0));
$this->assertArrayHasKey('handler.'.SecondMessage::class, $handlerMapping);
$secondReference = $handlerMapping['handler.'.SecondMessage::class]->getValues()[0];
$this->assertEquals(array(new Reference(HandlerWithGenerators::class), 'secondMessage'), $container->getDefinition($secondReference)->getArgument(0));
}
/**

0 comments on commit 44d4330

Please sign in to comment.