Skip to content

Commit

Permalink
bug #27651 [Messenger] Fixed MessengerPass::guessHandledClasses retur…
Browse files Browse the repository at this point in the history
…n type (massimilianobraglia)

This PR was merged into the 4.1 branch.

Discussion
----------

[Messenger] Fixed MessengerPass::guessHandledClasses return type

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

#27633 should have been merged to 4.1.

Commits
-------

d6b6e96 [Messenger] Fixed MessengerPass::guessHandledClasses return type
  • Loading branch information
nicolas-grekas committed Jun 20, 2018
2 parents 20147fc + d6b6e96 commit 389fa4d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -185,7 +185,7 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
}
}

private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId): array
private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId): iterable
{
if ($handlerClass->implementsInterface(MessageSubscriberInterface::class)) {
if (!$handledMessages = $handlerClass->getName()::getHandledMessages()) {
Expand Down
Expand Up @@ -274,6 +274,23 @@ public function testItRegistersSenderWithoutTagName()
$this->assertEquals(array(AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
}

public function testItShouldNotThrowIfGeneratorIsReturnedInsteadOfArray()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
$container
->register(HandlerWithGenerators::class, HandlerWithGenerators::class)
->addTag('messenger.message_handler')
;

(new MessengerPass())->process($container);

$handlerLocatorDefinition = $container->getDefinition($container->getDefinition("$busId.messenger.handler_resolver")->getArgument(0));
$handlerMapping = $handlerLocatorDefinition->getArgument(0);

$this->assertArrayHasKey('handler.'.DummyMessage::class, $handlerMapping);
$this->assertArrayHasKey('handler.'.SecondMessage::class, $handlerMapping);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Invalid sender "app.messenger.sender": class "Symfony\Component\Messenger\Tests\DependencyInjection\InvalidSender" must implement interface "Symfony\Component\Messenger\Transport\SenderInterface".
Expand Down Expand Up @@ -685,6 +702,23 @@ public function __invoke()
}
}

class HandlerWithGenerators implements MessageSubscriberInterface
{
public static function getHandledMessages(): iterable
{
yield DummyMessage::class => 'dummyMethod';
yield SecondMessage::class => 'secondMessage';
}

public function dummyMethod()
{
}

public function secondMessage()
{
}
}

class UselessMiddleware implements MiddlewareInterface
{
public function handle($message, callable $next)
Expand Down

0 comments on commit 389fa4d

Please sign in to comment.