Merge branch '2.7' into 2.8
* 2.7: [Console] Fix infinite loop on missing input
This commit is contained in:
commit
8d5c56348c
@ -19,6 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The QuestionHelper class provides helpers to interact with the user.
|
* The QuestionHelper class provides helpers to interact with the user.
|
||||||
@ -136,7 +137,7 @@ class QuestionHelper extends Helper
|
|||||||
if (false === $ret) {
|
if (false === $ret) {
|
||||||
$ret = fgets($inputStream, 4096);
|
$ret = fgets($inputStream, 4096);
|
||||||
if (false === $ret) {
|
if (false === $ret) {
|
||||||
throw new \RuntimeException('Aborted');
|
throw new RuntimeException('Aborted');
|
||||||
}
|
}
|
||||||
$ret = trim($ret);
|
$ret = trim($ret);
|
||||||
}
|
}
|
||||||
@ -399,6 +400,8 @@ class QuestionHelper extends Helper
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return call_user_func($question->getValidator(), $interviewer());
|
return call_user_func($question->getValidator(), $interviewer());
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
throw $e;
|
||||||
} catch (\Exception $error) {
|
} catch (\Exception $error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,6 +402,37 @@ class QuestionHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
|
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||||
|
* @expectedExceptionMessage Aborted
|
||||||
|
*/
|
||||||
|
public function testAskThrowsExceptionOnMissingInput()
|
||||||
|
{
|
||||||
|
$dialog = new QuestionHelper();
|
||||||
|
$dialog->setInputStream($this->getInputStream(''));
|
||||||
|
|
||||||
|
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), new Question('What\'s your name?'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||||
|
* @expectedExceptionMessage Aborted
|
||||||
|
*/
|
||||||
|
public function testAskThrowsExceptionOnMissingInputWithValidator()
|
||||||
|
{
|
||||||
|
$dialog = new QuestionHelper();
|
||||||
|
$dialog->setInputStream($this->getInputStream(''));
|
||||||
|
|
||||||
|
$question = new Question('What\'s your name?');
|
||||||
|
$question->setValidator(function () {
|
||||||
|
if (!$value) {
|
||||||
|
throw new \Exception('A value is required.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getInputStream($input)
|
protected function getInputStream($input)
|
||||||
{
|
{
|
||||||
$stream = fopen('php://memory', 'r+', false);
|
$stream = fopen('php://memory', 'r+', false);
|
||||||
|
@ -101,6 +101,18 @@ class SymfonyQuestionHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertOutputContains('Do you want a \?', $output);
|
$this->assertOutputContains('Do you want a \?', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||||
|
* @expectedExceptionMessage Aborted
|
||||||
|
*/
|
||||||
|
public function testAskThrowsExceptionOnMissingInput()
|
||||||
|
{
|
||||||
|
$dialog = new SymfonyQuestionHelper();
|
||||||
|
|
||||||
|
$dialog->setInputStream($this->getInputStream(''));
|
||||||
|
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), new Question('What\'s your name?'));
|
||||||
|
}
|
||||||
|
|
||||||
protected function getInputStream($input)
|
protected function getInputStream($input)
|
||||||
{
|
{
|
||||||
$stream = fopen('php://memory', 'r+', false);
|
$stream = fopen('php://memory', 'r+', false);
|
||||||
|
Reference in New Issue
Block a user