Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc758e22

Browse files
committed
feature#43683 [VarDumper] Add completion to server:dump command (alexandre-daubois)
This PR was merged into the 5.4 branch.Discussion----------[VarDumper] Add completion to server:dump command| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | Part of#43594| License | MIT| Doc PR | _NA_Commits-------c54a0a6 [Console] Add completion to server:dump command
2 parents85bf403 +c54a0a6 commitc758e22

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

‎src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespaceSymfony\Component\VarDumper\Command;
1313

1414
useSymfony\Component\Console\Command\Command;
15+
useSymfony\Component\Console\Completion\CompletionInput;
16+
useSymfony\Component\Console\Completion\CompletionSuggestions;
1517
useSymfony\Component\Console\Exception\InvalidArgumentException;
1618
useSymfony\Component\Console\Input\InputInterface;
1719
useSymfony\Component\Console\Input\InputOption;
@@ -55,10 +57,8 @@ public function __construct(DumpServer $server, array $descriptors = [])
5557

5658
protectedfunctionconfigure()
5759
{
58-
$availableFormats =implode(',',array_keys($this->descriptors));
59-
6060
$this
61-
->addOption('format',null, InputOption::VALUE_REQUIRED,sprintf('The output format (%s)',$availableFormats),'cli')
61+
->addOption('format',null, InputOption::VALUE_REQUIRED,sprintf('The output format (%s)',implode(',',$this->getAvailableFormats())),'cli')
6262
->setDescription(self::$defaultDescription)
6363
->setHelp(<<<'EOF'
6464
<info>%command.name%</info> starts a dump server that collects and displays
@@ -99,4 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9999

100100
return0;
101101
}
102+
103+
publicfunctioncomplete(CompletionInput$input,CompletionSuggestions$suggestions):void
104+
{
105+
if ($input->mustSuggestOptionValuesFor('format')) {
106+
$suggestions->suggestValues($this->getAvailableFormats());
107+
}
108+
}
109+
110+
privatefunctiongetAvailableFormats():array
111+
{
112+
returnarray_keys($this->descriptors);
113+
}
102114
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespaceSymfony\Component\VarDumper\Tests\Command;
4+
5+
usePHPUnit\Framework\TestCase;
6+
useSymfony\Component\Console\Tester\CommandCompletionTester;
7+
useSymfony\Component\VarDumper\Command\ServerDumpCommand;
8+
useSymfony\Component\VarDumper\Server\DumpServer;
9+
10+
class ServerDumpCommandTestextends TestCase
11+
{
12+
/**
13+
* @dataProvider provideCompletionSuggestions
14+
*/
15+
publicfunctiontestComplete(array$input,array$expectedSuggestions)
16+
{
17+
$tester =newCommandCompletionTester($this->createCommand());
18+
19+
$this->assertSame($expectedSuggestions,$tester->complete($input));
20+
}
21+
22+
publicfunctionprovideCompletionSuggestions()
23+
{
24+
yield'option --format' => [
25+
['--format',''],
26+
['cli','html'],
27+
];
28+
}
29+
30+
privatefunctioncreateCommand():ServerDumpCommand
31+
{
32+
returnnewServerDumpCommand($this->createMock(DumpServer::class));
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp