Skip to content

Commit 95242c2

Browse files
committed
Merge branch '5.0' into 5.1
* 5.0: Make PhpDocExtractor compatible with phpDocumentor v5 Reset question validator attempts only for actual stdin bumped Symfony version to 5.0.11 updated VERSION for 5.0.10 updated CHANGELOG for 5.0.10 bumped Symfony version to 4.4.11 updated VERSION for 4.4.10 updated CHANGELOG for 4.4.10
2 parents 0f0a271 + d981566 commit 95242c2

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

Helper/QuestionHelper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,16 @@ private function getShell()
508508

509509
private function isTty(): bool
510510
{
511-
$inputStream = !$this->inputStream && \defined('STDIN') ? STDIN : $this->inputStream;
511+
if (!\defined('STDIN')) {
512+
return true;
513+
}
512514

513515
if (\function_exists('stream_isatty')) {
514-
return stream_isatty($inputStream);
516+
return stream_isatty(fopen('php://input', 'r'));
515517
}
516518

517519
if (\function_exists('posix_isatty')) {
518-
return posix_isatty($inputStream);
520+
return posix_isatty(fopen('php://input', 'r'));
519521
}
520522

521523
return true;

Tests/Helper/QuestionHelperTest.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Tests\Helper;
1313

14+
use Symfony\Component\Console\Application;
1415
use Symfony\Component\Console\Exception\InvalidArgumentException;
1516
use Symfony\Component\Console\Formatter\OutputFormatter;
1617
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -21,6 +22,7 @@
2122
use Symfony\Component\Console\Question\ConfirmationQuestion;
2223
use Symfony\Component\Console\Question\Question;
2324
use Symfony\Component\Console\Terminal;
25+
use Symfony\Component\Console\Tester\ApplicationTester;
2426

2527
/**
2628
* @group tty
@@ -727,21 +729,36 @@ public function testAskThrowsExceptionOnMissingInputWithValidator()
727729
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), $question);
728730
}
729731

730-
public function testAskThrowsExceptionFromValidatorEarlyWhenTtyIsMissing()
732+
public function testQuestionValidatorRepeatsThePrompt()
731733
{
732-
$this->expectException('Exception');
733-
$this->expectExceptionMessage('Bar, not Foo');
734+
$tries = 0;
735+
$application = new Application();
736+
$application->setAutoExit(false);
737+
$application->register('question')
738+
->setCode(function ($input, $output) use (&$tries) {
739+
$question = new Question('This is a promptable question');
740+
$question->setValidator(function ($value) use (&$tries) {
741+
++$tries;
742+
if (!$value) {
743+
throw new \Exception();
744+
}
734745

735-
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
736-
$output->expects($this->once())->method('writeln');
746+
return $value;
747+
});
748+
749+
(new QuestionHelper())->ask($input, $output, $question);
737750

738-
(new QuestionHelper())->ask(
739-
$this->createStreamableInputInterfaceMock($this->getInputStream('Foo'), true),
740-
$output,
741-
(new Question('Q?'))->setHidden(true)->setValidator(function ($input) {
742-
throw new \Exception("Bar, not $input");
751+
return 0;
743752
})
744-
);
753+
;
754+
755+
$tester = new ApplicationTester($application);
756+
$tester->setInputs(['', 'not-empty']);
757+
758+
$statusCode = $tester->run(['command' => 'question'], ['interactive' => true]);
759+
760+
$this->assertSame(2, $tries);
761+
$this->assertSame($statusCode, 0);
745762
}
746763

747764
public function testEmptyChoices()

0 commit comments

Comments
 (0)