Skip to content

Commit cbec3df

Browse files
sez-openAmrouche Hamza
authored and
Amrouche Hamza
committed
fix debug:autowiringcommand
1 parent 9793522 commit cbec3df

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100
$hasAlias = [];
101101
$all = $input->getOption('all');
102102
$previousId = '-';
103+
$serviceIdsNb = \count($serviceIds);
103104
foreach ($serviceIds as $serviceId) {
104105
$text = [];
105106
if (0 !== strpos($serviceId, $previousId)) {
@@ -126,7 +127,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
126127
if ($serviceAlias->isDeprecated()) {
127128
$serviceLine .= ' - <fg=magenta>deprecated</>';
128129
}
130+
131+
} elseif ($all && $search && $serviceIdsNb > 0) {
132+
$io->text('Please use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.');
129133
} elseif (!$all) {
134+
if ($search) {
135+
$io->text(sprintf('%s more concrete service(s) would be displayed when adding the --all option.', $serviceIdsNb));
136+
}
130137
continue;
131138
}
132139
$text[] = $serviceLine;

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

+25
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,29 @@ public function testSearchNoResults()
7272
$this->assertContains('No autowirable classes or interfaces found matching "foo_fake"', $tester->getErrorOutput());
7373
$this->assertEquals(1, $tester->getStatusCode());
7474
}
75+
76+
public function testSearchNotAliasedService()
77+
{
78+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
79+
80+
$application = new Application(static::$kernel);
81+
$application->setAutoExit(false);
82+
83+
$tester = new ApplicationTester($application);
84+
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect']);
85+
86+
$this->assertContains('more concrete service(s) would be displayed when adding the --all option.', $tester->getDisplay());
87+
}
88+
89+
public function testSearchNotAliasedServiceWithAll()
90+
{
91+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
92+
93+
$application = new Application(static::$kernel);
94+
$application->setAutoExit(false);
95+
96+
$tester = new ApplicationTester($application);
97+
$tester->run(['command' => 'debug:autowiring', 'search' => 'redirect', '--all' => true]);
98+
$this->assertContains('Please use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle.', $tester->getDisplay());
99+
}
75100
}

0 commit comments

Comments
 (0)