Skip to content

Commit 5952489

Browse files
committed
Merge branch '4.2'
* 4.2: (45 commits) [Form] various minor fixes Ensure the parent process is always killed 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() [Routing] Fix: annotation loader ignores method's default values [HttpKernel] Fix DebugHandlersListener constructor docblock Skip Glob brace test when GLOB_BRACE is unavailable bumped Symfony version to 4.2.6 updated VERSION for 4.2.5 updated CHANGELOG for 4.2.5 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 fix testIgnoredAttributesInContext Re-generate icu 64.1 data Improve PHPdoc / IDE autocomplete for config tree builder [Bridge][Twig] DebugCommand - fix escaping and filter ...
2 parents f6f44ce + adb5118 commit 5952489

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-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) {

Tester/TesterTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ trait TesterTrait
3535
*/
3636
public function getDisplay($normalize = false)
3737
{
38+
if (null === $this->output) {
39+
throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?');
40+
}
41+
3842
rewind($this->output->getStream());
3943

4044
$display = stream_get_contents($this->output->getStream());

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)