Skip to content

Commit d2fece0

Browse files
committed
feature #43682 [FrameworkBundle] Add completion for config:dump-reference (StaffNowa)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Add completion for config:dump-reference | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #43594 | License | MIT | Doc PR | - Add completion for config:dump-reference Commits ------- cc6d0aee99 * config:dump-reference
2 parents 9139d80 + 01e34e7 commit d2fece0

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Command/ConfigDumpReferenceCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Config\Definition\ConfigurationInterface;
1515
use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
1616
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
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\Input\InputArgument;
1921
use Symfony\Component\Console\Input\InputInterface;
@@ -157,4 +159,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
157159

158160
return 0;
159161
}
162+
163+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
164+
{
165+
if ($input->mustSuggestArgumentValuesFor('name')) {
166+
$suggestions->suggestValues($this->getAvailableBundles());
167+
}
168+
169+
if ($input->mustSuggestOptionValuesFor('format')) {
170+
$suggestions->suggestValues($this->getAvailableFormatOptions());
171+
}
172+
}
173+
174+
private function getAvailableBundles(): array
175+
{
176+
$bundles = [];
177+
178+
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
179+
$bundles[] = $bundle->getName();
180+
$bundles[] = $bundle->getContainerExtension()->getAlias();
181+
}
182+
183+
return $bundles;
184+
}
185+
186+
private function getAvailableFormatOptions(): array
187+
{
188+
return ['yaml', 'xml'];
189+
}
160190
}

Tests/Functional/ConfigDumpReferenceCommandTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpReferenceCommand;
1415
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Component\Console\Input\ArrayInput;
1617
use Symfony\Component\Console\Output\NullOutput;
18+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1719
use Symfony\Component\Console\Tester\CommandTester;
1820

1921
/**
@@ -81,6 +83,23 @@ public function testDumpAtPathXml()
8183
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
8284
}
8385

86+
/**
87+
* @dataProvider provideCompletionSuggestions
88+
*/
89+
public function testComplete(array $input, array $expectedSuggestions)
90+
{
91+
$this->application->add(new ConfigDumpReferenceCommand());
92+
$tester = new CommandCompletionTester($this->application->get('config:dump-reference'));
93+
$suggestions = $tester->complete($input, 2);
94+
$this->assertSame($expectedSuggestions, $suggestions);
95+
}
96+
97+
public function provideCompletionSuggestions(): iterable
98+
{
99+
yield 'name' => [[''], ['DefaultConfigTestBundle', 'default_config_test', 'ExtensionWithoutConfigTestBundle', 'extension_without_config_test', 'FrameworkBundle', 'framework', 'TestBundle', 'test']];
100+
yield 'option --format' => [['--format', ''], ['yaml', 'xml']];
101+
}
102+
84103
private function createCommandTester(): CommandTester
85104
{
86105
$command = $this->application->find('config:dump-reference');

0 commit comments

Comments
 (0)