8000 [FrameworkBundle] debug:autowiring: Fix wrong display when using class_alias by weaverryan · Pull Request #36519 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$serviceIdsNb = 0;
foreach ($serviceIds as $serviceId) {
$text = [];
$resolvedServiceId = $serviceId;
if (0 !== strpos($serviceId, $previousId)) {
$text[] = '';
if ('' !== $description = Descriptor::getClassDescription($serviceId, $serviceId)) {
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
if (isset($hasAlias[$serviceId])) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

class_alias(
ClassAliasTargetClass::class,
__NAMESPACE__ . '\ClassAliasExampleClass'
);

if (false) {
class ClassAliasExampleClass
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

class ClassAliasTargetClass
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ public function testSearchNotAliasedServiceWithAll()
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect', '--all' => true]);
$this->assertStringContainsString('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.', $tester->getDisplay());
}

public function testNotConfusedByClassAliases()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);

$application = new Application(static::$kernel);
$application->setAutoExit(false);

$tester = new ApplicationTester($application);
$tester->run(['command' => 'debug:autowiring', 'search' => 'ClassAlias']);
$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.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
public: false
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass:
class: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass: '@public'
env:
class: stdClass
arguments:
Expand Down
0