bug #27651 [Messenger] Fixed MessengerPass::guessHandledClasses return 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
-------
d6b6e9658c
[Messenger] Fixed MessengerPass::guessHandledClasses return type
This commit is contained in:
commit
389fa4dc23
@ -185,7 +185,7 @@ class MessengerPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
@ -274,6 +274,23 @@ class MessengerPassTest extends TestCase
|
||||
$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".
|
||||
@ -685,6 +702,23 @@ class HandleNoMessageHandler implements MessageSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user