[Console] Fix QuestionHelperTest
- When using the `InputInterface` mock with interactive option, asking a ChoiceQuestion without specifying max attempts nor a default value led to an infinite loop when invalid values are submitted. In case there is something wrong in tests, it wasn't obvious to understand what's happening, as the process was constantly waiting for inputs. - `testAmbiguousChoiceFromChoicelist` test was wrong as the autocompleter filled the value and the test was never triggered (+max attempt issue).
This commit is contained in:
parent
ba719d18dd
commit
6a0308d752
@ -227,15 +227,20 @@ class QuestionHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dialog->setHelperSet($helperSet);
|
$dialog->setHelperSet($helperSet);
|
||||||
|
|
||||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||||
|
$question->setMaxAttempts(1);
|
||||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||||
|
|
||||||
$this->assertSame($expectedValue, $answer);
|
$this->assertSame($expectedValue, $answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage The provided answer is ambiguous. Value should be one of env_2 or env_3.
|
||||||
|
*/
|
||||||
public function testAmbiguousChoiceFromChoicelist()
|
public function testAmbiguousChoiceFromChoicelist()
|
||||||
{
|
{
|
||||||
$possibleChoices = array(
|
$possibleChoices = array(
|
||||||
'env_1' => 'My environment 1',
|
'env_1' => 'My first environment',
|
||||||
'env_2' => 'My environment',
|
'env_2' => 'My environment',
|
||||||
'env_3' => 'My environment',
|
'env_3' => 'My environment',
|
||||||
);
|
);
|
||||||
@ -246,12 +251,9 @@ class QuestionHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dialog->setHelperSet($helperSet);
|
$dialog->setHelperSet($helperSet);
|
||||||
|
|
||||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||||
|
$question->setMaxAttempts(1);
|
||||||
|
|
||||||
try {
|
|
||||||
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
$this->assertEquals('The provided answer is ambiguous. Value should be one of env_2 or env_3.', $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function answerProvider()
|
public function answerProvider()
|
||||||
|
Reference in New Issue
Block a user