Skip to content

Commit fd54cc6

Browse files
committed
feature #43640 [Console] Add completion to messenger:setup-transports command (Tayfun74)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Console] Add completion to messenger:setup-transports command | Q | A | ------------- | --- | Branch? | 5.4 <!-- see below --> | Bug fix? | no | New feature? | yes<!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | #43594 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | no <!-- required for new features --> - Add completion for command messenger:setup-transports (transport) Commits ------- 733aaa8db1 [Console] Add completion to messenger:setup-transports command
2 parents 6b8f145 + f6a4ef5 commit fd54cc6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Command/SetupTransportsCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Psr\Container\ContainerInterface;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Input\InputArgument;
1719
use Symfony\Component\Console\Input\InputInterface;
1820
use Symfony\Component\Console\Output\OutputInterface;
@@ -81,4 +83,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8183

8284
return 0;
8385
}
86+
87+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
88+
{
89+
if ($input->mustSuggestArgumentValuesFor('transport')) {
90+
$suggestions->suggestValues($this->transportNames);
91+
92+
return;
93+
}
94+
}
8495
}

Tests/Command/SetupTransportsCommandTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1617
use Symfony\Component\Console\Tester\CommandTester;
1718
use Symfony\Component\DependencyInjection\ServiceLocator;
1819
use Symfony\Component\Messenger\Command\SetupTransportsCommand;
@@ -87,4 +88,21 @@ public function testReceiverNameArgumentNotFound()
8788
$tester = new CommandTester($command);
8889
$tester->execute(['transport' => 'not_found']);
8990
}
91+
92+
/**
93+
* @dataProvider provideCompletionSuggestions
94+
*/
95+
public function testComplete(array $input, array $expectedSuggestions)
96+
{
97+
$serviceLocator = $this->createMock(ServiceLocator::class);
98+
$command = new SetupTransportsCommand($serviceLocator, ['amqp', 'other_transport']);
99+
$tester = new CommandCompletionTester($command);
100+
$suggestions = $tester->complete($input);
101+
$this->assertSame($expectedSuggestions, $suggestions);
102+
}
103+
104+
public function provideCompletionSuggestions()
105+
{
106+
yield 'transport' => [[''], ['amqp', 'other_transport']];
107+
}
90108
}

0 commit comments

Comments
 (0)