Skip to content

Commit

Permalink
Fixing a bug where class_alias would cause incorrect items in debug:a…
Browse files Browse the repository at this point in the history
…utowiring
  • Loading branch information
weaverryan committed Apr 21, 2020
1 parent 2a92dd3 commit 36a0972
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
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
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

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

if (false) {
class ClassAliasExampleClass
{
}
}
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

class ClassAliasTargetClass
{
}
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', '--all' => true]);
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass (public)', $tester->getDisplay());
}
}
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 comments on commit 36a0972

Please sign in to comment.