Skip to content

Commit

Permalink
[Console] fix "data lost during stream conversion" with QuestionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 5, 2020
1 parent 2732dda commit 0ec319e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -462,10 +462,6 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
$error = null;
$attempts = $question->getMaxAttempts();

if (null === $attempts && !$this->isTty()) {
$attempts = 1;
}

while (null === $attempts || $attempts--) {
if (null !== $error) {
$this->writeError($output, $error);
Expand All @@ -477,6 +473,8 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
throw $e;
} catch (\Exception $error) {
}

$attempts = $attempts ?? -(int) $this->isTty();
}

throw $error;
Expand Down Expand Up @@ -517,7 +515,7 @@ private function isTty(): bool
return stream_isatty($inputStream);
}

if (!\function_exists('posix_isatty')) {
if (\function_exists('posix_isatty')) {
return posix_isatty($inputStream);
}

Expand Down
Expand Up @@ -446,7 +446,7 @@ public function testAskConfirmation($question, $expected, $default = true)
{
$dialog = new QuestionHelper();

$inputStream = $this->getInputStream($question."\n");
$inputStream = $this->getInputStream($question."\n".$question."\n");
$question = new ConfirmationQuestion('Do you like French fries?', $default);
$this->assertEquals($expected, $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
}
Expand Down

0 comments on commit 0ec319e

Please sign in to comment.