Skip to content

Commit adb5118

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: [Form] various minor fixes bugfix: the terminal state was wrong and not reseted [Console] Fix inconsistent result for choice questions in non-interactive mode Define null return type for Constraint::getDefaultOption() [HttpKernel] Fix DebugHandlersListener constructor docblock Skip Glob brace test when GLOB_BRACE is unavailable bumped Symfony version to 3.4.25 updated VERSION for 3.4.24 update CONTRIBUTORS for 3.4.24 updated CHANGELOG for 3.4.24 [EventDispatcher] cleanup
2 parents 24206af + 7d3072a commit adb5118

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Helper/QuestionHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4949
if (!$input->isInteractive()) {
5050
$default = $question->getDefault();
5151

52-
if (null !== $default && $question instanceof ChoiceQuestion) {
52+
if (null === $default) {
53+
return $default;
54+
}
55+
56+
if ($validator = $question->getValidator()) {
57+
return \call_user_func($question->getValidator(), $default);
58+
} elseif ($question instanceof ChoiceQuestion) {
5359
$choices = $question->getChoices();
5460

5561
if (!$question->isMultiselect()) {
@@ -215,6 +221,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
215221

216222
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
217223
if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
224+
shell_exec(sprintf('stty %s', $sttyMode));
218225
throw new RuntimeException('Aborted.');
219226
} elseif ("\177" === $c) { // Backspace Character
220227
if (0 === $numMatches && 0 !== $i) {

Tests/Helper/QuestionHelperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public function testAskChoiceNonInteractive()
137137
$question->setMultiselect(true);
138138
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
139139

140+
$question = new ChoiceQuestion('Who are your favorite superheros?', ['a' => 'Batman', 'b' => 'Superman'], 'a');
141+
$this->assertSame('a', $questionHelper->ask($this->createStreamableInputInterfaceMock('', false), $this->createOutputInterface(), $question), 'ChoiceQuestion validator returns the key if it\'s a string');
142+
140143
try {
141144
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
142145
$question->setMultiselect(true);

0 commit comments

Comments
 (0)