Skip to content

Navigation Menu

Sign in
Appearance settings

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 c3522c4

Browse filesBrowse files
committed
feature #43653 [PasswordHasher] Add autocompletion for security commands (noniagriconomie)
This PR was merged into the 5.4 branch. Discussion ---------- [PasswordHasher] Add autocompletion for security commands | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Ref #43594 | License | MIT | Doc PR | Related to #43594 (comment) I have a question regarding `@wouterj` 's comment on the issue Also, the `password` is the first argument right now, should we swap it to be after `user-class`? Still WIP, I am using `fish` and want to test as well #43641 Commits ------- 49f45a9 [Console] Add autocompletion for security commands
2 parents 375a89a + 49f45a9 commit c3522c4
Copy full SHA for c3522c4

File tree

2 files changed

+40
-0
lines changed
Filter options

2 files changed

+40
-0
lines changed

‎src/Symfony/Component/PasswordHasher/Command/UserPasswordHashCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Command/UserPasswordHashCommand.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\PasswordHasher\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\Exception\RuntimeException;
1719
use Symfony\Component\Console\Input\InputArgument;
@@ -168,6 +170,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
168170
return 0;
169171
}
170172

173+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
174+
{
175+
if ($input->mustSuggestArgumentValuesFor('user-class')) {
176+
$suggestions->suggestValues($this->userClasses);
177+
178+
return;
179+
}
180+
}
181+
171182
/**
172183
* Create the password question to ask the user for the password to be hashed.
173184
*/

‎src/Symfony/Component/PasswordHasher/Tests/Command/UserPasswordHashCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Tests/Command/UserPasswordHashCommandTest.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\PasswordHasher\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Component\PasswordHasher\Command\UserPasswordHashCommand;
1718
use Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher;
@@ -286,6 +287,34 @@ public function testThrowsExceptionOnNoConfiguredHashers()
286287
], ['interactive' => false]);
287288
}
288289

290+
/**
291+
* @dataProvider provideCompletionSuggestions
292+
*/
293+
public function testCompletionSuggestions(array $input, array $expectedSuggestions)
294+
{
295+
if (!class_exists(CommandCompletionTester::class)) {
296+
$this->markTestSkipped('Test command completion requires symfony/console 5.4+.');
297+
}
298+
299+
$command = new UserPasswordHashCommand($this->createMock(PasswordHasherFactoryInterface::class), ['App\Entity\User']);
300+
$tester = new CommandCompletionTester($command);
301+
302+
$this->assertSame($expectedSuggestions, $tester->complete($input));
303+
}
304+
305+
public function provideCompletionSuggestions()
306+
{
307+
yield 'user_class_empty' => [
308+
[''],
309+
['App\Entity\User'],
310+
];
311+
312+
yield 'user_class_given' => [
313+
['App'],
314+
['App\Entity\User'],
315+
];
316+
}
317+
289318
protected function setUp(): void
290319
{
291320
$this->colSize = getenv('COLUMNS');

0 commit comments

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