Skip to content

Commit 5c143ba

Browse files
committed
bug symfony#61501 [Console] Fix testing multiline question (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [Console] Fix testing multiline question | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#58910 | License | MIT Commits ------- b08751e [Console] Fix testing multiline question
2 parents 5b9a1fe + b08751e commit 5c143ba

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,16 @@ private function readInput($inputStream, Question $question): string|false
527527
$ret = '';
528528
$cp = $this->setIOCodepage();
529529
while (false !== ($char = fgetc($multiLineStreamReader))) {
530-
if (\PHP_EOL === "{$ret}{$char}") {
530+
if ("\x4" === $char || \PHP_EOL === "{$ret}{$char}") {
531531
break;
532532
}
533533
$ret .= $char;
534534
}
535535

536+
if (stream_get_meta_data($inputStream)['seekable']) {
537+
fseek($inputStream, ftell($multiLineStreamReader));
538+
}
539+
536540
return $this->resetIOCodepage($cp, $ret);
537541
}
538542

src/Symfony/Component/Console/Tester/TesterTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ private static function createStream(array $inputs)
169169

170170
foreach ($inputs as $input) {
171171
fwrite($stream, $input.\PHP_EOL);
172+
173+
if (str_contains($input, \PHP_EOL)) {
174+
fwrite($stream, "\x4");
175+
}
172176
}
173177

174178
rewind($stream);

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public function testAskMultilineResponseWithWithCursorInMiddleOfSeekableInputStr
519519
$question->setMultiline(true);
520520

521521
$this->assertSame("some\ninput", $dialog->ask($this->createStreamableInputInterfaceMock($response), $this->createOutputInterface(), $question));
522-
$this->assertSame(8, ftell($response));
522+
$this->assertSame(18, ftell($response));
523523
}
524524

525525
/**

0 commit comments

Comments
 (0)