Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4: (26 commits)
  [AssetMapper] Fix: also download files referenced by url() in CSS
  [AssetMapper] Fix eager imports are not deduplicated
  [Mime] Add `TemplatedEmail::$locale` to the serialized props
  fix tests
  add return types to test fixtures
  fix merge
  [Cache] Get TRUNCATE statement from platform
  do not detect the deserialization_path context value twice
  fix detecting the database server version
  [Cache] Add url decoding of password in `RedisTrait` DSN
  [Serializer] Remove incompatible type declaration with PHP 7.2
  [Serializer] Fix test
  Fix denormalizing empty string into object|null parameter
  [PropertyInfo] Fixed promoted property type detection for `PhpStanExtractor`
  [Serializer] Move discrimination to abstract
  [Serializer] Fix deserialization_path missing using contructor
  [Serializer] Fix access to private when Ignore
  [AssetMapper] Adding an option (true by default) to not publish dot files
  [AssetMapper] Fixing out-of-date test on Windows
  [HttpKernel] Fix logging deprecations to the "php" channel when channel "deprecation" is not defined
  ...
  • Loading branch information
fabpot committed Nov 25, 2023
2 parents 5c972ca + a6f32d0 commit 2451778
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
5 changes: 3 additions & 2 deletions DependencyInjection/MessengerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private function registerHandlers(ContainerBuilder $container, array $busIds): v
unset($options['handles']);
$priority = $options['priority'] ?? 0;
$method = $options['method'] ?? '__invoke';
$fromTransport = $options['from_transport'] ?? '';

if (isset($options['bus'])) {
if (!\in_array($options['bus'], $busIds)) {
Expand All @@ -121,10 +122,10 @@ private function registerHandlers(ContainerBuilder $container, array $busIds): v
throw new RuntimeException(sprintf('Invalid handler service "%s": method "%s::%s()" does not exist.', $serviceId, $r->getName(), $method));
}

if ('__invoke' !== $method) {
if ('__invoke' !== $method || '' !== $fromTransport) {
$wrapperDefinition = (new Definition('Closure'))->addArgument([new Reference($serviceId), $method])->setFactory('Closure::fromCallable');

$definitions[$definitionId = '.messenger.method_on_object_wrapper.'.ContainerBuilder::hash($message.':'.$priority.':'.$serviceId.':'.$method)] = $wrapperDefinition;
$definitions[$definitionId = '.messenger.method_on_object_wrapper.'.ContainerBuilder::hash($message.':'.$priority.':'.$serviceId.':'.$method.':'.$fromTransport)] = $wrapperDefinition;
} else {
$definitionId = $serviceId;
}
Expand Down
20 changes: 17 additions & 3 deletions Tests/DependencyInjection/MessengerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Symfony\Component\Messenger\Tests\Fixtures\SecondMessage;
use Symfony\Component\Messenger\Tests\Fixtures\TaggedDummyHandler;
use Symfony\Component\Messenger\Tests\Fixtures\TaggedDummyHandlerWithUnionTypes;
use Symfony\Component\Messenger\Tests\Fixtures\ThirdMessage;
use Symfony\Component\Messenger\Tests\Fixtures\UnionBuiltinTypeArgumentHandler;
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeArgumentHandler;
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeOneMessage;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function testFromTransportViaTagAttribute()
$container = $this->getContainerBuilder($busId = 'message_bus');
$container
->register(DummyHandler::class, DummyHandler::class)
->addTag('messenger.message_handler', ['from_transport' => 'async'])
->addTag('messenger.message_handler', ['from_transport' => 'async', 'method' => '__invoke'])
;

(new MessengerPass())->process($container);
Expand All @@ -108,7 +109,7 @@ public function testFromTransportViaTagAttribute()
$handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
$this->assertCount(1, $handlerDescriptionMapping);

$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [DummyHandler::class], [['from_transport' => 'async']]);
$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [[DummyHandler::class, '__invoke']], [['from_transport' => 'async']]);
}

public function testHandledMessageTypeResolvedWithMethodAndNoHandlesViaTagAttributes()
Expand Down Expand Up @@ -160,7 +161,7 @@ public function testTaggedMessageHandler()
$this->assertSame(HandlersLocator::class, $handlersLocatorDefinition->getClass());

$handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
$this->assertCount(2, $handlerDescriptionMapping);
$this->assertCount(3, $handlerDescriptionMapping);

$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [TaggedDummyHandler::class], [[]]);
$this->assertHandlerDescriptor(
Expand All @@ -169,6 +170,19 @@ public function testTaggedMessageHandler()
SecondMessage::class,
[[TaggedDummyHandler::class, 'handleSecondMessage']]
);
$this->assertHandlerDescriptor(
$container,
$handlerDescriptionMapping,
ThirdMessage::class,
[
[TaggedDummyHandler::class, 'handleThirdMessage'],
[TaggedDummyHandler::class, 'handleThirdMessage'],
],
[
['from_transport' => 'a'],
['from_transport' => 'b'],
],
);
}

public function testTaggedMessageHandlerWithUnionTypes()
Expand Down
6 changes: 6 additions & 0 deletions Tests/Fixtures/TaggedDummyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public function __invoke(DummyMessage $message)
public function handleSecondMessage(SecondMessage $message)
{
}

#[AsMessageHandler(fromTransport: 'a')]
#[AsMessageHandler(fromTransport: 'b')]
public function handleThirdMessage(ThirdMessage $message): void
{
}
}
7 changes: 7 additions & 0 deletions Tests/Fixtures/ThirdMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Messenger\Tests\Fixtures;

class ThirdMessage
{
}

0 comments on commit 2451778

Please sign in to comment.