Skip to content

Commit ac32825

Browse files
committed
Add suggestions for the option 'format' of lints commands: twig, yaml and xliff
1 parent 251888d commit ac32825

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Command/LintCommand.php

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

1414
use Symfony\Component\Console\CI\GithubActionReporter;
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\Exception\RuntimeException;
1820
use Symfony\Component\Console\Input\InputArgument;
@@ -277,4 +279,11 @@ private function isReadable(string $fileOrDirectory): bool
277279

278280
return $default($fileOrDirectory);
279281
}
282+
283+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
284+
{
285+
if ($input->mustSuggestOptionValuesFor('format')) {
286+
$suggestions->suggestValues(['txt', 'json', 'github']);
287+
}
288+
}
280289
}

Tests/Command/LintCommandTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\CI\GithubActionReporter;
17+
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1820
use Symfony\Component\Console\Tester\CommandTester;
1921
use Symfony\Component\Yaml\Command\LintCommand;
2022

@@ -163,6 +165,21 @@ public function testLintFileNotReadable()
163165
$tester->execute(['filename' => $filename], ['decorated' => false]);
164166
}
165167

168+
/**
169+
* @dataProvider provideCompletionSuggestions
170+
*/
171+
public function testComplete(array $input, array $expectedSuggestions)
172+
{
173+
$tester = new CommandCompletionTester($this->createCommand());
174+
175+
$this->assertSame($expectedSuggestions, $tester->complete($input));
176+
}
177+
178+
public function provideCompletionSuggestions()
179+
{
180+
yield 'option' => [['--format', ''], ['txt', 'json', 'github']];
181+
}
182+
166183
private function createFile($content): string
167184
{
168185
$filename = tempnam(sys_get_temp_dir().'/framework-yml-lint-test', 'sf-');
@@ -173,13 +190,17 @@ private function createFile($content): string
173190
return $filename;
174191
}
175192

176-
protected function createCommandTester(): CommandTester
193+
protected function createCommand(): Command
177194
{
178195
$application = new Application();
179196
$application->add(new LintCommand());
180-
$command = $application->find('lint:yaml');
181197

182-
return new CommandTester($command);
198+
return $application->find('lint:yaml');
199+
}
200+
201+
protected function createCommandTester(): CommandTester
202+
{
203+
return new CommandTester($this->createCommand());
183204
}
184205

185206
protected function setUp(): void

0 commit comments

Comments
 (0)