Skip to content
Permalink
Browse files

bug #31445 [Messenger] Making cache rebuild correctly when message su…

…bscribers change (weaverryan)

This PR was merged into the 4.2 branch.

Discussion
----------

[Messenger] Making cache rebuild correctly when message subscribers change

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31409
| License       | MIT
| Doc PR        | not needed

An edge-case that's identical to `EventSubscriberInterface`: when the return value of `getHandledMessages()` changes, the container needs to be rebuilt.

If you're wondering why these checks aren't in their own resource class, see #25984 - it's something we probably should do, but haven't done yet.

Commits
-------

d88446b Making cache rebuild correctly with MessageSubscriberInterface return values
  • Loading branch information...
nicolas-grekas committed May 11, 2019
2 parents 3ae1e80 + d88446b commit b9d3135b1f6ff8e3a1998ab3b6528c696c1539ef
@@ -13,6 +13,7 @@
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface as LegacyServiceSubscriberInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
/**
@@ -164,6 +165,13 @@ private function generateSignature(\ReflectionClass $class)
yield print_r($class->name::getSubscribedEvents(), true);
}
if (interface_exists(MessageSubscriberInterface::class, false) && $class->isSubclassOf(MessageSubscriberInterface::class)) {
yield MessageSubscriberInterface::class;
foreach ($class->name::getHandledMessages() as $key => $value) {
yield $key.print_r($value, true);
}
}
if (interface_exists(LegacyServiceSubscriberInterface::class, false) && $class->isSubclassOf(LegacyServiceSubscriberInterface::class)) {
yield LegacyServiceSubscriberInterface::class;
yield print_r([$class->name, 'getSubscribedServices'](), true);
@@ -15,6 +15,7 @@
use Symfony\Component\Config\Resource\ReflectionClassResource;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
class ReflectionClassResourceTest extends TestCase
{
@@ -147,6 +148,24 @@ public function testEventSubscriber()
$this->assertTrue($res->isFresh(0));
}
public function testMessageSubscriber()
{
$res = new ReflectionClassResource(new \ReflectionClass(TestMessageSubscriber::class));
$this->assertTrue($res->isFresh(0));
TestMessageSubscriberConfigHolder::$handledMessages = ['SomeMessageClass' => []];
$this->assertFalse($res->isFresh(0));
$res = new ReflectionClassResource(new \ReflectionClass(TestMessageSubscriber::class));
$this->assertTrue($res->isFresh(0));
TestMessageSubscriberConfigHolder::$handledMessages = ['OtherMessageClass' => []];
$this->assertFalse($res->isFresh(0));
$res = new ReflectionClassResource(new \ReflectionClass(TestMessageSubscriber::class));
$this->assertTrue($res->isFresh(0));
}
public function testServiceSubscriber()
{
$res = new ReflectionClassResource(new \ReflectionClass(TestServiceSubscriber::class));
@@ -174,6 +193,20 @@ public static function getSubscribedEvents()
}
}
class TestMessageSubscriber implements MessageSubscriberInterface
{
public static function getHandledMessages(): iterable
{
foreach (TestMessageSubscriberConfigHolder::$handledMessages as $key => $subscribedMessage) {
yield $key => $subscribedMessage;
}
}
}
class TestMessageSubscriberConfigHolder
{
public static $handledMessages = [];
}
class TestServiceSubscriber implements ServiceSubscriberInterface
{
public static $subscribedServices = [];
@@ -24,6 +24,7 @@
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/event-dispatcher": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0",
"symfony/messenger": "~4.1",
"symfony/yaml": "~3.4|~4.0"
},
"conflict": {

0 comments on commit b9d3135

Please sign in to comment.
You can’t perform that action at this time.