Skip to content

Commit f6a4ef5

Browse files
Tayfun74fabpot
authored andcommitted
[Console] Add completion to messenger:setup-transports command
1 parent 469b3dd commit f6a4ef5

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)