bug #26875 [Console] Don't go past exact matches when autocompleting (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[Console] Don't go past exact matches when autocompleting
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21789
| License | MIT
| Doc PR | -
Commits
-------
adba79a
[Console] Don't go past exact matches when autocompleting
This commit is contained in:
commit
10674688da
@ -284,7 +284,7 @@ class QuestionHelper extends Helper
|
|||||||
|
|
||||||
foreach ($autocomplete as $value) {
|
foreach ($autocomplete as $value) {
|
||||||
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
|
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
|
||||||
if (0 === strpos($value, $ret) && $i !== strlen($value)) {
|
if (0 === strpos($value, $ret)) {
|
||||||
$matches[$numMatches++] = $value;
|
$matches[$numMatches++] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,30 @@ class QuestionHelperTest extends TestCase
|
|||||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAskWithAutocompleteWithExactMatch()
|
||||||
|
{
|
||||||
|
if (!$this->hasSttyAvailable()) {
|
||||||
|
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||||
|
}
|
||||||
|
|
||||||
|
$inputStream = $this->getInputStream("b\n");
|
||||||
|
|
||||||
|
$possibleChoices = array(
|
||||||
|
'a' => 'berlin',
|
||||||
|
'b' => 'copenhagen',
|
||||||
|
'c' => 'amsterdam',
|
||||||
|
);
|
||||||
|
|
||||||
|
$dialog = new QuestionHelper();
|
||||||
|
$dialog->setInputStream($inputStream);
|
||||||
|
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
|
||||||
|
|
||||||
|
$question = new ChoiceQuestion('Please select a city', $possibleChoices);
|
||||||
|
$question->setMaxAttempts(1);
|
||||||
|
|
||||||
|
$this->assertSame('b', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAutocompleteWithTrailingBackslash()
|
public function testAutocompleteWithTrailingBackslash()
|
||||||
{
|
{
|
||||||
if (!$this->hasSttyAvailable()) {
|
if (!$this->hasSttyAvailable()) {
|
||||||
|
Reference in New Issue
Block a user