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