8000 feature #43598 [Console] add suggestions for debug commands: firewall… · symfony/framework-bundle@bccee1d · GitHub
[go: up one dir, main page]

Skip to content

Commit bccee1d

Browse files
committed
feature #43598 [Console] add suggestions for debug commands: firewall, form, messenger, router (IonBazan)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] add suggestions for debug commands: firewall, form, messenger, router | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #43594 | License | MIT | Doc PR | - Adding Bash completion for following commands: - `debug:firewall` - `debug:form` - `debug:messenger` - `debug:router` ~Waiting for #43596 to be merged first as it adds testing utilities and `DescriptorHelper::getFormats()`.~ Commits ------- eaf9461722 add suggestions for debug:firewall, debug:form, debug:messenger, debug:router
2 parents 93340c8 + 4db3f9d commit bccee1d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Command/RouterDebugCommand.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Exception\InvalidArgumentException;
1719
use Symfony\Component\Console\Input\InputArgument;
1820
use Symfony\Component\Console\Input\InputInterface;
@@ -131,4 +133,18 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
131133

132134
return $foundRoutesNames;
133135
}
136+
137+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
138+
{
139+
if ($input->mustSuggestArgumentValuesFor('name')) {
140+
$suggestions->suggestValues(array_keys($this->router->getRouteCollection()->all()));
141+
142+
return;
143+
}
144+
145+
if ($input->mustSuggestOptionValuesFor('format')) {
146+
$helper = new DescriptorHelper();
147+
$suggestions->suggestValues($helper->getFormats());
148+
}
149+
}
134150
}

Tests/Functional/RouterDebugCommandTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617

1718
/**
@@ -69,6 +70,37 @@ public function testSearchWithThrow()
6970
$tester->execute(['name' => 'gerard'], ['interactive' => true]);
7071
}
7172

73+
/**
74+
* @dataProvider provideCompletionSuggestions
75+
*/
76+
public function testComplete(array $input, array $expectedSuggestions)
77+
{
78+
if (!class_exists(CommandCompletionTester::class)) {
79+
$this->markTestSkipped('Test command completion requires symfony/console 5.4+.');
80+
}
81+
82+
$tester = new CommandCompletionTester($this->application->get('debug:router'));
83+
$this->assertSame($expectedSuggestions, $tester->complete($input));
84+
}
85+
86+
public function provideCompletionSuggestions()
87+
{
88+
yield 'option --format' => [
89+
['--format', ''],
90+
['txt', 'xml', 'json', 'md'],
91+
];
92+
93+
yield 'route_name' => [
94+
[''],
95+
[
96+
'routerdebug_session_welcome',
97+
'routerdebug_session_welcome_name',
98+
'routerdebug_session_logout',
99+
'routerdebug_test',
100+
],
101+
];
102+
}
103+
72104
private function createCommandTester(): CommandTester
73105
{
74106
$command = $this->application->get('debug:router');

0 commit comments

Comments
 (0)
0