Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit afd9b92

Browse filesBrowse files
author
Adrien Jourdier
committed
Fix debug:autowiring with named arguments
1 parent 8c1d58d commit afd9b92
Copy full SHA for afd9b92

File tree

Expand file treeCollapse file tree

2 files changed

+9
-47
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-47
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php
+4-38Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\Console\Input\InputOption;
2121
use Symfony\Component\Console\Output\OutputInterface;
2222
use Symfony\Component\Console\Style\SymfonyStyle;
23-
use Symfony\Component\DependencyInjection\ContainerBuilder;
2423
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
2524

2625
/**
@@ -80,10 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8079
$errorIo = $io->getErrorStyle();
8180

8281
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());
83-
$serviceIds = $this->getServices($builder);
82+
$serviceIds = $builder->getServiceIds();
83+
$serviceIds = array_filter($serviceIds, [$this, 'filterToServiceTypes']);
8484

8585
if ($search = $input->getArgument('search')) {
86-
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search);
86+
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff $]++/', '', $search);
8787

8888
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
8989
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && !str_starts_with($serviceId, '.');
@@ -170,42 +170,8 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
170170
{
171171
if ($input->mustSuggestArgumentValuesFor('search')) {
172172
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());
173-
$serviceIds = $this->getServices($builder);
174-
175-
$services = $this->getServicesCompletion($serviceIds, $input->getArgument('search'), $builder);
176-
177-
$suggestions->suggestValues($services);
178-
}
179-
}
180-
181-
private function getServices(ContainerBuilder $builder): array
182-
{
183-
$serviceIds = $builder->getServiceIds();
184-
185-
return array_filter($serviceIds, [$this, 'filterToServiceTypes']);
186-
}
187173

188-
private function getServicesCompletion(array $serviceIds, string $search, ContainerBuilder $builder): array
189-
{
190-
$services = [];
191-
foreach ($serviceIds as $serviceId) {
192-
$service = str_replace('\\', '', $serviceId);
193-
$service = str_replace('.', '', $service);
194-
195-
if (
196-
false === stripos($service, $search) ||
197-
str_starts_with($service, '.') ||
198-
false !== strpos($service, ' ')) {
199-
continue;
200-
}
201-
202-
$services[] = $serviceId;
203-
204-
if ($builder->hasAlias($serviceId)) {
205-
$services[] = (string) $builder->getAlias($serviceId);
206-
}
174+
$suggestions->suggestValues(array_filter($builder->getServiceIds(), [$this, 'filterToServiceTypes']));
207175
}
208-
209-
return $services;
210176
}
211177
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/DebugAutowiringCommandTest.php
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,20 @@ public function testNotConfusedByClassAliases()
117117
*/
118118
public function testComplete(array $input, array $expectedSuggestions)
119119
{
120-
$kernel = static::bootKernel(['test_case' => 'BundlePaths']);
120+
$kernel = static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
121121
$command = (new Application($kernel))->add(new DebugAutowiringCommand());
122122

123123
$tester = new CommandCompletionTester($command);
124124

125125
$suggestions = $tester->complete($input);
126126

127-
$this->assertSame($expectedSuggestions, $suggestions);
127+
foreach ($expectedSuggestions as $expectedSuggestion) {
128+
$this->assertContains($expectedSuggestion, $suggestions);
129+
}
128130
}
129131

130132
public function provideCompletionSuggestions(): \Generator
131133
{
132-
yield 'search' => [
133-
['twig'],
134-
[
135-
'Twig\Environment',
136-
'twig',
137-
],
138-
];
134+
yield 'search' => [[''], ['SessionHandlerInterface', 'Psr\\Log\\LoggerInterface', 'Psr\\Container\\ContainerInterface $parameterBag']];
139135
}
140136
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.