Skip to content

Commit ceb825c

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 2abf3c9 + 0fd9ecf commit ceb825c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
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\Attribute\AsCommand;
1515
use Symfony\Component\Console\CI\GithubActionReporter;
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;
@@ -274,4 +276,11 @@ private function getContext(string $template, int $line, int $context = 3)
274276

275277
return $result;
276278
}
279+
280+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
281+
{
282+
if ($input->mustSuggestOptionValuesFor('format')) {
283+
$suggestions->suggestValues(['txt', 'json', 'github']);
284+
}
285+
}
277286
}

Tests/Command/LintCommandTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Command\LintCommand;
1616
use Symfony\Component\Console\Application;
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 Twig\Environment;
2022
use Twig\Loader\FilesystemLoader;
@@ -134,7 +136,27 @@ public function testLintAutodetectsGithubActionEnvironment()
134136
}
135137
}
136138

139+
/**
140+
* @dataProvider provideCompletionSuggestions
141+
*/
142+
public function testComplete(array $input, array $expectedSuggestions)
143+
{
144+
$tester = new CommandCompletionTester($this->createCommand());
145+
146+
$this->assertSame($expectedSuggestions, $tester->complete($input));
147+
}
148+
149+
public function provideCompletionSuggestions()
150+
{
151+
yield 'option' => [['--format', ''], ['txt', 'json', 'github']];
152+
}
153+
137154
private function createCommandTester(): CommandTester
155+
{
156+
return new CommandTester($this->createCommand());
157+
}
158+
159+
private function createCommand(): Command
138160
{
139161
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
140162
$environment->addFilter(new TwigFilter('deprecated_filter', function ($v) {
@@ -145,9 +167,8 @@ private function createCommandTester(): CommandTester
145167

146168
$application = new Application();
147169
$application->add($command);
148-
$command = $application->find('lint:twig');
149170

150-
return new CommandTester($command);
171+
return $application->find('lint:twig');
151172
}
152173

153174
private function createFile($content): string

0 commit comments

Comments
 (0)