8000 Fixing a bug where class_alias would cause incorrect items in debug:a… · symfony/symfony@36a0972 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36a0972

Browse files
committed
Fixing a bug where class_alias would cause incorrect items in debug:autowiring
1 parent 2a92dd3 commit 36a0972

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103103
$serviceIdsNb = 0;
104104
foreach ($serviceIds as $serviceId) {
105105
$text = [];
106+
$resolvedServiceId = $serviceId;
106107
if (0 !== strpos($serviceId, $previousId)) {
107108
$text[] = '';
108-
if ('' !== $description = Descriptor::getClassDescription($serviceId, $serviceId)) {
109+
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
109110
if (isset($hasAlias[$serviceId])) {
110111
continue;
111112
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
4+
5+
class_alias(
6+
ClassAliasTargetClass::class,
7+
__NAMESPACE__ . '\ClassAliasExampleClass'
8+
);
9+
10+
if (false) {
11+
class ClassAliasExampleClass
12+
{
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
4+
5+
class ClassAliasTargetClass
6+
{
7+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/DebugAutowiringCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,16 @@ public function testSearchNotAliasedServiceWithAll()
9797
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect', '--all' => true]);
9898
$this->assertStringContainsString('Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.', $tester->getDisplay());
9999
}
100+
101+
public function testNotConfusedByClassAliases()
102+
{
103+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
104+
105+
$application = new Application(static::$kernel);
106+
$application->setAutoExit(false);
107+
108+
$tester = new ApplicationTester($application);
109+
$tester->run(['command' => 'debug:autowiring', 'search' => 'ClassAlias', '--all' => true]);
110+
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass (public)', $tester->getDisplay());
111+
}
100112
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
public: false
1414
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass:
1515
class: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass
16+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass: '@public'
1617
env:
1718
class: stdClass
1819
arguments:

0 commit comments

Comments
 (0)
0