Skip to content
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

[FrameworkBundle] debug:autowiring: Fix wrong display when using class_alias #36519

Merged

Conversation

weaverryan
Copy link
Member

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets None
License MIT
Doc PR not needed

Imagine that FooInterface is an alias, but it is deprecated and so has a class_alias to BarInterface. Currently, debug:autowiring will actually print that's the autowiring alias is BarInterface, despite there being no such id in the container.

@nicolas-grekas originally (on purpose) made the 2nd argument to Descriptor::getClassDescription() be passed by reference for this exact feature - 56aab09 - but I can't figure out why. This change (which effectively removes the by-reference modifying) made no existing tests fail.

Discovered this because the whole deprecatedDoctrine\Common\Persistence\ManagerRegistry vs newer Doctrine\Persistence\ManagerRegistry causes the issue.

Thanks!


$tester = new ApplicationTester($application);
$tester->run(['command' => 'debug:autowiring', 'search' => 'ClassAlias', '--all' => true]);
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass (public)', $tester->getDisplay());
Copy link
Member Author

Choose a reason for hiding this comment

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

Before the patch, the output was simple:

Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasTargetClass

It would resolve ClassAliasExampleClass to ClassAliasTargetClass. To make matters worse, because ClassAliasTargetClass is not an alias name in the system (it's not even a service in the system), it doesn't print the service id (or show up unless you pass --all) because it looks (incorrectly) like a concrete service.

@weaverryan weaverryan force-pushed the debug-autowiring-class-aliases branch from 36a0972 to d34b437 Compare April 21, 2020 18:43
@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Apr 21, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Since you have tests and a use case, and also because I don't remember, you win :)

@nicolas-grekas nicolas-grekas changed the title Debug:autowiring: Fix wrong display when using class_alias [FrameworkBundle] debug:autowiring: Fix wrong display when using class_alias Apr 21, 2020
@nicolas-grekas
Copy link
Member

Thank you @weaverryan.

@nicolas-grekas nicolas-grekas merged commit 2d7b0b8 into symfony:4.4 Apr 23, 2020
@weaverryan weaverryan deleted the debug-autowiring-class-aliases branch April 24, 2020 10:11
This was referenced Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants