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 9c3247c

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

File tree

2 files changed

+22
-2
lines changed
Filter options

2 files changed

+22
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Question/Question.php
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
+20Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.