[Console] ChoiceQuestion must have choices

This commit is contained in:
Roland Franssen 2017-05-22 10:45:15 +02:00 committed by Fabien Potencier
parent 103414623c
commit 96e307fd5c
2 changed files with 13 additions and 0 deletions

View File

@ -32,6 +32,10 @@ class ChoiceQuestion extends Question
*/
public function __construct($question, array $choices, $default = null)
{
if (!$choices) {
throw new \LogicException('Choice question must have at least 1 choice available.');
}
parent::__construct($question, $default);
$this->choices = $choices;

View File

@ -434,6 +434,15 @@ class QuestionHelperTest extends TestCase
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Choice question must have at least 1 choice available.
*/
public function testEmptyChoices()
{
new ChoiceQuestion('Question', array(), 'irrelevant');
}
protected function getInputStream($input)
{
$stream = fopen('php://memory', 'r+', false);