10000 bug #22847 [Console] ChoiceQuestion must have choices (ro0NL) · symfony/symfony@20485d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20485d1

Browse files
committed
bug #22847 [Console] ChoiceQuestion must have choices (ro0NL)
This PR was squashed before being merged into the 2.7 branch (closes #22847). Discussion ---------- [Console] ChoiceQuestion must have choices | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22842 | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> <!-- ![image](https://cloud.githubusercontent.com/assets/1047696/26301309/1bfa52ca-3ee1-11e7-883b-f627f16e9d2f.png) --> Commits ------- 96e307f [Console] ChoiceQuestion must have choices
2 parents 979bd62 + 96e307f commit 20485d1

File tree

2 files changed

+13
-0
lines changed
  • src/Symfony/Component/Console
    • Question
    • Tests/Helper

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
@@ -465,6 +465,15 @@ public function testAskThrowsExceptionOnMissingInputWithValidator()
465465
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
466466
}
467467

468+
/**
469+
* @expectedException \LogicException
470+
* @expectedExceptionMessage Choice question must have at least 1 choice available.
471+
*/
472+
public function testEmptyChoices()
473+
{
474+
new ChoiceQuestion('Question', array(), 'irrelevant');
475+
}
476+
468477
protected function getInputStream($input)
469478
{
470479
$stream = fopen('php://memory', 'r+', false);

0 commit comments

Comments
 (0)
0