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
-------

96e307fd5c [Console] ChoiceQuestion must have choices
This commit is contained in:
Fabien Potencier 2017-05-28 06:43:15 -07:00
commit 20485d1f9b
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

@ -465,6 +465,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);