Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Command;

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

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

$serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && !str_starts_with($serviceId, '.');
});
Expand Down Expand Up @@ -162,4 +165,13 @@ private function getFileLink(string $class): string

return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('search')) {
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());

$suggestions->suggestValues(array_filter($builder->getServiceIds(), [$this, 'filterToServiceTypes']));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\Console\Tester\CommandCompletionTester;

/**
* @group functional
Expand Down Expand Up @@ -109,4 +111,26 @@ public function testNotConfusedByClassAliases()
$tester->run(['command' => 'debug:autowiring', 'search' => 'ClassAlias']);
$this->assertStringContainsString('Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ClassAliasExampleClass', $tester->getDisplay());
}

/**
* @dataProvider provideCompletionSuggestions
*/
public function testComplete(array $input, array $expectedSuggestions)
{
$kernel = static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
$command = (new Application($kernel))->add(new DebugAutowiringCommand());

$tester = new CommandCompletionTester($command);

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

foreach ($expectedSuggestions as $expectedSuggestion) {
$this->assertContains($expectedSuggestion, $suggestions);
}
}

public function provideCompletionSuggestions(): \Generator
{
yield 'search' => [[''], ['SessionHandlerInterface', 'Psr\\Log\\LoggerInterface', 'Psr\\Container\\ContainerInterface $parameterBag']];
}
}