Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\PasswordHasher\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -168,6 +170,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('user-class')) {
$suggestions->suggestValues($this->userClasses);

return;
}
}

/**
* Create the password question to ask the user for the password to be hashed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\PasswordHasher\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\PasswordHasher\Command\UserPasswordHashCommand;
use Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher;
Expand Down Expand Up @@ -286,6 +287,34 @@ public function testThrowsExceptionOnNoConfiguredHashers()
], ['interactive' => false]);
}

/**
* @dataProvider provideCompletionSuggestions
*/
public function testCompletionSuggestions(array $input, array $expectedSuggestions)
{
if (!class_exists(CommandCompletionTester::class)) {
$this->markTestSkipped('Test command completion requires symfony/console 5.4+.');
}

$command = new UserPasswordHashCommand($this->createMock(PasswordHasherFactoryInterface::class), ['App\Entity\User']);
$tester = new CommandCompletionTester($command);

$this->assertSame($expectedSuggestions, $tester->complete($input));
}

public function provideCompletionSuggestions()
{
yield 'user_class_empty' => [
[''],
['App\Entity\User'],
];

yield 'user_class_given' => [
['App'],
['App\Entity\User'],
];
}

protected function setUp(): void
{
$this->colSize = getenv('COLUMNS');
Expand Down