diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index acb8a8564..f3a99edf2 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -12,11 +12,12 @@ namespace Composer\IO; +use Composer\Question\StrictConfirmationQuestion; +use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\HelperSet; -use Composer\Question\StrictConfirmationQuestion; +use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question; /** @@ -281,11 +282,14 @@ class ConsoleIO extends BaseIO */ public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) { - if ($this->isInteractive()) { - return $this->helperSet->get('dialog')->select($this->getErrorOutput(), $question, $choices, $default, $attempts, $errorMessage, $multiselect); - } + /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ + $helper = $this->helperSet->get('question'); + $question = new ChoiceQuestion($question, $choices, $default); + $question->setMaxAttempts($attempts ?: null); // IOInterface requires false, and Question requires null or int + $question->setErrorMessage($errorMessage); + $question->setMultiselect($multiselect); - return $default; + return $helper->ask($this->input, $this->getErrorOutput(), $question); } /** diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index ff96a011f..518b6d0e1 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -229,27 +229,32 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + + $helperMock + ->expects($this->once()) + ->method('ask') + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\Question') + ) + ; + + $setMock + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; $inputMock->expects($this->once()) ->method('isInteractive') - ->will($this->returnValue(true)); - $dialogMock->expects($this->once()) - ->method('select') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Select item'), - $this->equalTo(array("item1", "item2")), - $this->equalTo(null), - $this->equalTo(false), - $this->equalTo("Error message"), - $this->equalTo(true)); - $helperMock->expects($this->once()) - ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->will($this->returnValue(true)) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->select('Select item', array("item1", "item2"), null, false, "Error message", true); }