From 774be36b9dbe1aac41020225d8992b158bd0caf1 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 21 Apr 2020 14:33:50 -0400 Subject: [PATCH] Fixing a bug where class_alias would cause incorrect items in debug:autowiring --- Command/DebugAutowiringCommand.php | 3 ++- Tests/Fixtures/ClassAliasExampleClass.php | 14 ++++++++++++++ Tests/Fixtures/ClassAliasTargetClass.php | 7 +++++++ Tests/Functional/DebugAutowiringCommandTest.php | 12 ++++++++++++ Tests/Functional/app/ContainerDebug/config.yml | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Tests/Fixtures/ClassAliasExampleClass.php create mode 100644 Tests/Fixtures/ClassAliasTargetClass.php diff --git a/Command/DebugAutowiringCommand.php b/Command/DebugAutowiringCommand.php index 04d391da1..32bd630f3 100644 --- a/Command/DebugAutowiringCommand.php +++ b/Command/DebugAutowiringCommand.php @@ -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; } diff --git a/Tests/Fixtures/ClassAliasExampleClass.php b/Tests/Fixtures/ClassAliasExampleClass.php new file mode 100644 index 000000000..c12986585 --- /dev/null +++ b/Tests/Fixtures/ClassAliasExampleClass.php @@ -0,0 +1,14 @@ +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()); + } } diff --git a/Tests/Functional/app/ContainerDebug/config.yml b/Tests/Functional/app/ContainerDebug/config.yml index 0cc73dbc8..25c1c7842 100644 --- a/Tests/Functional/app/ContainerDebug/config.yml +++ b/Tests/Functional/app/ContainerDebug/config.yml @@ -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: