Skip to content

Commit 3857e0c

Browse files
Merge branch '5.4' into 6.0
* 5.4: (46 commits) move username/password fix to non-deprecated Connection class cs fix [VarDumper] Fix dumping twig templates found in exceptions do not replace definition arguments that have not been configured fix Console tests on Windows [Validator] Add translations for CIDR constraint [Dotenv] Fix testLoadEnv() to start from a fresh context [Console] Add completion to server:dump command bug #42194 [RateLimiter] fix: sliding window policy to use microtime [Validator] Update validators.sr_Cyrl.xlf [Validator] Update validators.sr_Latn.xlf Add suggestions for the option 'format' of lints commands: twig, yaml and xliff [VarDumper] Add support for Fiber uzb translation Update validators.uz.xlf Fix logging of impersonator introduced in 5.3 [Console] Add show proxified command class in completion debug skip command completion tests with older Symfony Console versions [Uid] Allow use autocompletion [Console] Add completion to messenger:setup-transports command ...
2 parents b516d90 + ac32825 commit 3857e0c

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
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Console\CI\GithubActionReporter;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Completion\CompletionInput;
18+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1719
use Symfony\Component\Console\Exception\InvalidArgumentException;
1820
use Symfony\Component\Console\Exception\RuntimeException;
1921
use Symfony\Component\Console\Input\InputArgument;
@@ -271,4 +273,11 @@ private function isReadable(string $fileOrDirectory): bool
271273

272274
return $default($fileOrDirectory);
273275
}
276+
277+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
278+
{
279+
if ($input->mustSuggestOptionValuesFor('format')) {
280+
$suggestions->suggestValues(['txt', 'json', 'github']);
281+
}
282+
}
274283
}

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)