diff --git a/src/Symfony/Component/Console/Question/ChoiceQuestion.php b/src/Symfony/Component/Console/Question/ChoiceQuestion.php index e5b6ff4ad7217..f07ace4b161ec 100644 --- a/src/Symfony/Component/Console/Question/ChoiceQuestion.php +++ b/src/Symfony/Component/Console/Question/ChoiceQuestion.php @@ -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; diff --git a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php index 49ba0ee06c79a..2309965deeff8 100644 --- a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php @@ -434,6 +434,15 @@ public function testAskThrowsExceptionOnMissingInputWithValidator() $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);