Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0945e82

Browse files
Merge branch '6.1' into 6.2
* 6.1: [Mailer] Include all transports' debug messages in RoundRobin transport exception [FrameworkBundle] fix: fix help message Fix HtmlSanitizer default configuration behavior for allowed schemes Use relative timestamps [Cache] Fix dealing with ext-redis' multi/exec returning a bool [Messenger][Amqp] Added missing rpc_timeout option [Serializer] Prevent GetSetMethodNormalizer from creating invalid magic method call [HttpFoundation] Fix dumping array cookies [WebProfilerBundle] Fix dump header not being displayed TraceableHttpClient: increase decorator's priority Use static methods inside data providers [FrameworkBundle] Allow configuring `framework.exceptions` with a config builder bug #48313 [Mime] Fix MessagePart serialization [HttpKernel][ErrorHandler] Fix reading the SYMFONY_IDE env var [ErrorHandler][DebugClassLoader] Fix some new return types support Fix getting the name of closures on PHP 8.1.11+ [Translator] Fix typo "internal" / "interval" fix dumping top-level tagged values [Console] Fix clear line with question in section
2 parents a42df13 + 578809f commit 0945e82

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Output/ConsoleSectionOutput.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public function getVisibleContent(): string
102102
return implode('', \array_slice($this->content, -$this->maxHeight));
103103
}
104104

105+
/**
106+
* @internal
107+
*/
108+
public function incrementLines()
109+
{
110+
++$this->lines;
111+
}
112+
105113
/**
106114
* @internal
107115
*/

Style/SymfonyStyle.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Console\Helper\TableSeparator;
2424
use Symfony\Component\Console\Input\InputInterface;
2525
use Symfony\Component\Console\Output\ConsoleOutputInterface;
26+
use Symfony\Component\Console\Output\ConsoleSectionOutput;
2627
use Symfony\Component\Console\Output\OutputInterface;
2728
use Symfony\Component\Console\Output\TrimmedBufferOutput;
2829
use Symfony\Component\Console\Question\ChoiceQuestion;
@@ -300,6 +301,11 @@ public function askQuestion(Question $question): mixed
300301
if ($this->input->isInteractive()) {
301302
$this->newLine();
302303
$this->bufferedOutput->write("\n");
304+
if ($this->output instanceof ConsoleSectionOutput) {
305+
// add one line more to the ConsoleSectionOutput because of the `return` to submit the input
306+
// this is relevant when a `ConsoleSectionOutput::clear` is called.
307+
$this->output->incrementLines();
308+
}
303309
}
304310

305311
return $answer;

Tests/Style/SymfonyStyleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
use Symfony\Component\Console\Exception\RuntimeException;
1717
use Symfony\Component\Console\Formatter\OutputFormatter;
1818
use Symfony\Component\Console\Input\ArrayInput;
19+
use Symfony\Component\Console\Input\Input;
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2122
use Symfony\Component\Console\Output\ConsoleSectionOutput;
2223
use Symfony\Component\Console\Output\NullOutput;
2324
use Symfony\Component\Console\Output\OutputInterface;
25+
use Symfony\Component\Console\Output\StreamOutput;
2426
use Symfony\Component\Console\Style\SymfonyStyle;
2527
use Symfony\Component\Console\Tester\CommandTester;
2628

@@ -181,4 +183,38 @@ public function testMemoryConsumption()
181183

182184
$this->assertSame(0, memory_get_usage() - $start);
183185
}
186+
187+
public function testAskAndClearExpectFullSectionCleared()
188+
{
189+
$answer = 'Answer';
190+
$inputStream = fopen('php://memory', 'r+');
191+
fwrite($inputStream, $answer.\PHP_EOL);
192+
rewind($inputStream);
193+
$input = $this->createMock(Input::class);
194+
$sections = [];
195+
$output = new ConsoleSectionOutput(fopen('php://memory', 'r+', false), $sections, StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatter());
196+
$input
197+
->method('isInteractive')
198+
->willReturn(true);
199+
$input
200+
->method('getStream')
201+
->willReturn($inputStream);
202+
203+
$style = new SymfonyStyle($input, $output);
204+
205+
$style->write('foo');
206+
$givenAnswer = $style->ask('Dummy question?');
207+
$output->write('bar');
208+
$output->clear();
209+
210+
rewind($output->getStream());
211+
$this->assertEquals($answer, $givenAnswer);
212+
$this->assertEquals(
213+
'foo'.\PHP_EOL. // write foo
214+
\PHP_EOL.\PHP_EOL.\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL.\PHP_EOL. // question
215+
'bar'.\PHP_EOL. // write bar
216+
"\033[10A\033[0J", // clear 10 lines (9 output lines and one from the answer input return)
217+
stream_get_contents($output->getStream())
218+
);
219+
}
184220
}

0 commit comments

Comments
 (0)