public function QuestionHelperTest::testAskAndValidate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Tests/Helper/QuestionHelperTest.php \Symfony\Component\Console\Tests\Helper\QuestionHelperTest::testAskAndValidate()
File
- vendor/
symfony/ console/ Tests/ Helper/ QuestionHelperTest.php, line 187
Class
- QuestionHelperTest
- @group tty
Namespace
Symfony\Component\Console\Tests\HelperCode
public function testAskAndValidate() {
$dialog = new QuestionHelper();
$helperSet = new HelperSet(array(
new FormatterHelper(),
));
$dialog
->setHelperSet($helperSet);
$error = 'This is not a color!';
$validator = function ($color) use ($error) {
if (!in_array($color, array(
'white',
'black',
))) {
throw new \InvalidArgumentException($error);
}
return $color;
};
$question = new Question('What color was the white horse of Henry IV?', 'white');
$question
->setValidator($validator);
$question
->setMaxAttempts(2);
$dialog
->setInputStream($this
->getInputStream("\nblack\n"));
$this
->assertEquals('white', $dialog
->ask($this
->createInputInterfaceMock(), $this
->createOutputInterface(), $question));
$this
->assertEquals('black', $dialog
->ask($this
->createInputInterfaceMock(), $this
->createOutputInterface(), $question));
$dialog
->setInputStream($this
->getInputStream("green\nyellow\norange\n"));
try {
$dialog
->ask($this
->createInputInterfaceMock(), $this
->createOutputInterface(), $question);
$this
->fail();
} catch (\InvalidArgumentException $e) {
$this
->assertEquals($error, $e
->getMessage());
}
}