Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] Making cache rebuild correctly when message subscribers change #31445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Making cache rebuild correctly with MessageSubscriberInterface return…
… values
  • Loading branch information
weaverryan committed May 9, 2019
commit d88446be072ea3466eda4673f1611364cac5528a
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 = [];
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered that testEventSubscriber() and testServiceSubscriber() are invalid. Part of the signature of ReflectionClassResource is the constants and their values. So, to purely test that the resource becomes stale when a static method is called, we must do that without modifying any constants.

Those other 2 methods need to be fixed in 3.4 - you can comment out the code in ReflectionClassResource for each and they still pass.


class TestServiceSubscriber implements ServiceSubscriberInterface
{
public static $subscribedServices = [];
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Config/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.