Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96e307f

Browse files
ro0NLfabpot
authored andcommitted
[Console] ChoiceQuestion must have choices
1 parent 1034146 commit 96e307f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ChoiceQuestion extends Question
3232
*/
3333
public function __construct($question, array $choices, $default = null)
3434
{
35+
if (!$choices) {
36+
throw new \LogicException('Choice question must have at least 1 choice available.');
37+
}
38+
3539
parent::__construct($question, $default);
3640

3741
$this->choices = $choices;

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ public function testAskThrowsExceptionOnMissingInputWithValidator()
434434
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
435435
}
436436

437+
/**
438+
* @expectedException \LogicException
439+
* @expectedExceptionMessage Choice question must have at least 1 choice available.
440+
*/
441+
public function testEmptyChoices()
442+
{
443+
new ChoiceQuestion('Question', array(), 'irrelevant');
444+
}
445+
437446
protected function getInputStream($input)
438447
{
439448
$stream = fopen('php://memory', 'r+', false);

0 commit comments

Comments
 (0)