Skip to content

Commit 9c3247c

Browse files
committed
[Console] Fix an autocompletion question helper issue with non-sequentially indexed choices
1 parent a1c95f7 commit 9c3247c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/Console/Question/Question.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function getAutocompleterValues()
135135
*/
136136
public function setAutocompleterValues($values)
137137
{
138-
if (is_array($values) && $this->isAssoc($values)) {
139-
$values = array_merge(array_keys($values), array_values($values));
138+
if (is_array($values)) {
139+
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
140140
}
141141

142142
if (null !== $values && !is_array($values)) {

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ public function testAskWithAutocomplete()
135135
$this->assertEquals('FooBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
136136
}
137137

138+
public function testAskWithAutocompleteWithNonSequentialKeys()
139+
{
140+
if (!$this->hasSttyAvailable()) {
141+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
142+
}
143+
144+
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
145+
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
146+
147+
$dialog = new QuestionHelper();
148+
$dialog->setInputStream($inputStream);
149+
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
150+
151+
$question = new ChoiceQuestion('Please select a bundle', array(1 => 'AcmeDemoBundle', 4 => 'AsseticBundle'));
152+
$question->setMaxAttempts(1);
153+
154+
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
155+
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
156+
}
157+
138158
public function testAskHiddenResponse()
139159
{
140160
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy