10000 feat: add completion for DebugAutowiring search argument · symfony/symfony@ef8c518 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef8c518

Browse files
eclairiafabpot
authored andcommitted
feat: add completion for DebugAutowiring search argument
1 parent bd08495 commit ef8c518

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
15+
use Symfony\Component\Console\Completion\CompletionInput;
16+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1517
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1618
use Symfony\Component\Console\Input\InputArgument;
1719
use Symfony\Component\Console\Input\InputInterface;
@@ -81,7 +83,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8183
$serviceIds = array_filter($serviceIds, [$this, 'filterToServiceTypes']);
8284

8385
if ($search = $input->getArgument('search')) {
84-
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search);
86+
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff $]++/', '', $search);
87+
8588
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
8689
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && !str_starts_with($serviceId, '.');
8790
});
@@ -162,4 +165,13 @@ private function getFileLink(string $class): string
162165

163166
return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
164167
}
168+
169+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
170+
{
171+
if ($input->mustSuggestArgumentValuesFor('search')) {
172+
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());
173+
174+
$suggestions->suggestValues(array_filter($builder->getServiceIds(), [$this, 'filterToServiceTypes']));
175+
}
176+
}
165177
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand;
1415
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Tester\ApplicationTester;
17+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1618

1719
/**
1820
* @group functional
@@ -109,4 +111,26 @@ public function testNotConfusedByClassAliases()
109111
$tester->run(['command' => 'debug:autowiring', 'search' => 'ClassAlias']);
110112
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass', $tester->getDisplay());
111113
}
114+
115+
/**
116+
* @dataProvider provideCompletionSuggestions
117+
*/
118+
public function testComplete(array $input, array $expectedSuggestions)
119+
{
120+
$kernel = static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
121+
$command = (new Application($kernel))->add(new DebugAutowiringCommand());
122+
123+
$tester = new CommandCompletionTester($command);
124+
125+
$suggestions = $tester->complete($input);
126+
127+
foreach ($expectedSuggestions as $expectedSuggestion) {
128+
$this->assertContains($expectedSuggestion, $suggestions);
129+
}
130+
}
131+
132+
public function provideCompletionSuggestions(): \Generator
133+
{
134+
yield 'search' => [[''], ['SessionHandlerInterface', 'Psr\\Log\\LoggerInterface', 'Psr\\Container\\ContainerInterface $parameterBag']];
135+
}
112136
}

0 commit comments

Comments
 (0)
0