|
15 | 15 | use Symfony\Bridge\Twig\Command\DebugCommand;
|
16 | 16 | use Symfony\Component\Console\Application;
|
17 | 17 | use Symfony\Component\Console\Exception\InvalidArgumentException;
|
| 18 | +use Symfony\Component\Console\Tester\CommandCompletionTester; |
18 | 19 | use Symfony\Component\Console\Tester\CommandTester;
|
19 | 20 | use Twig\Environment;
|
20 | 21 | use Twig\Loader\ChainLoader;
|
@@ -293,6 +294,33 @@ public function testWithFilter()
|
293 | 294 | $this->assertNotSame($display1, $display2);
|
294 | 295 | }
|
295 | 296 |
|
| 297 | + /** |
| 298 | + * @dataProvider provideCompletionSuggestions |
| 299 | + */ |
| 300 | + public function testComplete(array $input, array $expectedSuggestions) |
| 301 | + { |
| 302 | + if (!class_exists(CommandCompletionTester::class)) { |
| 303 | + $this->markTestSkipped('Test command completion requires symfony/console 5.4+.'); |
| 304 | + } |
| 305 | + |
| 306 | + $projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; |
| 307 | + $loader = new FilesystemLoader([], $projectDir); |
| 308 | + $environment = new Environment($loader); |
| 309 | + |
| 310 | + $application = new Application(); |
| 311 | + $application->add(new DebugCommand($environment, $projectDir, [], null, null)); |
| 312 | + |
| 313 | + $tester = new CommandCompletionTester($application->find('debug:twig')); |
| 314 | + $suggestions = $tester->complete($input, 2); |
| 315 | + $this->assertSame($expectedSuggestions, $suggestions); |
| 316 | + } |
| 317 | + |
| 318 | + public function provideCompletionSuggestions(): iterable |
| 319 | + { |
| 320 | + yield 'name' => [['email'], []]; |
| 321 | + yield 'option --format' => [['--format', ''], ['text', 'json']]; |
| 322 | + } |
| 323 | + |
296 | 324 | private function createCommandTester(array $paths = [], array $bundleMetadata = [], string $defaultPath = null, bool $useChainLoader = false, array $globals = []): CommandTester
|
297 | 325 | {
|
298 | 326 | $projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
|
|
0 commit comments