Skip to content

Commit

Permalink
bug #27820 [Messenger] Fix a bug when having more than one named hand…
Browse files Browse the repository at this point in the history
…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 44d4330
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -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;
}
}
}
Expand Down
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 44d4330

Please sign in to comment.