Skip to content

Navigation Menu

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

Appearance settings

Commit f377018

Browse filesBrowse files
committed
feature #43846 Add completion for debug:twig (StaffNowa)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Add completion for debug:twig | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #43594 | License | MIT | Doc PR | - Add completion for debug:twig Commits ------- 68c5e3c Add completion for debug:twig
2 parents b7fc0d5 + 68c5e3c commit f377018
Copy full SHA for f377018

File tree

2 files changed

+41
-0
lines changed
Filter options

2 files changed

+41
-0
lines changed

‎src/Symfony/Bridge/Twig/Command/DebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/DebugCommand.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bridge\Twig\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Completion\CompletionInput;
16+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1517
use Symfony\Component\Console\Exception\InvalidArgumentException;
1618
use Symfony\Component\Console\Formatter\OutputFormatter;
1719
use Symfony\Component\Console\Input\InputArgument;
@@ -110,6 +112,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
110112
return 0;
111113
}
112114

115+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
116+
{
117+
if ($input->mustSuggestArgumentValuesFor('name')) {
118+
$suggestions->suggestValues(array_keys($this->getLoaderPaths()));
119+
}
120+
121+
if ($input->mustSuggestOptionValuesFor('format')) {
122+
$suggestions->suggestValues(['text', 'json']);
123+
}
124+
}
125+
113126
private function displayPathsText(SymfonyStyle $io, string $name)
114127
{
115128
$file = new \ArrayIterator($this->findTemplateFiles($name));

‎src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Twig\Command\DebugCommand;
1616
use Symfony\Component\Console\Application;
1717
use Symfony\Component\Console\Exception\InvalidArgumentException;
18+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1819
use Symfony\Component\Console\Tester\CommandTester;
1920
use Twig\Environment;
2021
use Twig\Loader\ChainLoader;
@@ -293,6 +294,33 @@ public function testWithFilter()
293294
$this->assertNotSame($display1, $display2);
294295
}
295296

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+
296324
private function createCommandTester(array $paths = [], array $bundleMetadata = [], string $defaultPath = null, bool $useChainLoader = false, array $globals = []): CommandTester
297325
{
298326
$projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.