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 ef8c518

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

File tree

2 files changed

+37
-1
lines changed
Filter options

2 files changed

+37
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php
+13-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/DebugAutowiringCommandTest.php
+24Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.