Skip to content

Commit

Permalink
bug #18078 [Console] Fix an autocompletion question helper issue with…
Browse files Browse the repository at this point in the history
… non-sequentially indexed choices (jakzal)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fix an autocompletion question helper issue with non-sequentially indexed choices

| Q             | A
| ------------- | ---
| Branch        | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18001
| License       | MIT
| Doc PR        | -

Commits
-------

9c3247c [Console] Fix an autocompletion question helper issue with non-sequentially indexed choices
  • Loading branch information
fabpot committed Mar 9, 2016
2 parents a1c95f7 + 9c3247c commit efd40e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Question/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public function getAutocompleterValues()
*/
public function setAutocompleterValues($values)
{
if (is_array($values) && $this->isAssoc($values)) {
$values = array_merge(array_keys($values), array_values($values));
if (is_array($values)) {
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
}

if (null !== $values && !is_array($values)) {
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ public function testAskWithAutocomplete()
$this->assertEquals('FooBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
}

public function testAskWithAutocompleteWithNonSequentialKeys()
{
if (!$this->hasSttyAvailable()) {
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
}

// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");

$dialog = new QuestionHelper();
$dialog->setInputStream($inputStream);
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));

$question = new ChoiceQuestion('Please select a bundle', array(1 => 'AcmeDemoBundle', 4 => 'AsseticBundle'));
$question->setMaxAttempts(1);

$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
}

public function testAskHiddenResponse()
{
if ('\\' === DIRECTORY_SEPARATOR) {
Expand Down

0 comments on commit efd40e4

Please sign in to comment.