From 7bb0309decaed84bb0dfa5dd9e9cdf7d4d804d72 Mon Sep 17 00:00:00 2001 From: maxbeckers Date: Thu, 3 Nov 2022 08:29:05 +0100 Subject: [PATCH 1/3] [Console] Fix clear line with question in section --- Output/ConsoleSectionOutput.php | 8 +++++++ Style/SymfonyStyle.php | 6 ++++++ Tests/Style/SymfonyStyleTest.php | 36 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index d4c2f20c7..527c1a224 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -87,6 +87,14 @@ public function addContent(string $input) } } + /** + * @internal + */ + public function incrementLines() + { + ++$this->lines; + } + /** * {@inheritdoc} */ diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index f13c313d3..1de3b552f 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -22,6 +22,7 @@ use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; +use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\TrimmedBufferOutput; use Symfony\Component\Console\Question\ChoiceQuestion; @@ -350,6 +351,11 @@ public function askQuestion(Question $question): mixed if ($this->input->isInteractive()) { $this->newLine(); $this->bufferedOutput->write("\n"); + if ($this->output instanceof ConsoleSectionOutput) { + // add one line more to the ConsoleSectionOutput because of the `return` to submit the input + // this is relevant when a `ConsoleSectionOutput::clear` is called. + $this->output->incrementLines(); + } } return $answer; diff --git a/Tests/Style/SymfonyStyleTest.php b/Tests/Style/SymfonyStyleTest.php index 74c240340..3441449da 100644 --- a/Tests/Style/SymfonyStyleTest.php +++ b/Tests/Style/SymfonyStyleTest.php @@ -16,11 +16,13 @@ use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\Input; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Tester\CommandTester; @@ -181,4 +183,38 @@ public function testMemoryConsumption() $this->assertSame(0, memory_get_usage() - $start); } + + public function testAskAndClearExpectFullSectionCleared() + { + $answer = 'Answer'; + $inputStream = fopen('php://memory', 'r+'); + fwrite($inputStream, $answer.\PHP_EOL); + rewind($inputStream); + $input = $this->createMock(Input::class); + $sections = []; + $output = new ConsoleSectionOutput(fopen('php://memory', 'r+', false), $sections, StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatter()); + $input + ->method('isInteractive') + ->willReturn(true); + $input + ->method('getStream') + ->willReturn($inputStream); + + $style = new SymfonyStyle($input, $output); + + $style->write('foo'); + $givenAnswer = $style->ask('Dummy question?'); + $output->write('bar'); + $output->clear(); + + rewind($output->getStream()); + $this->assertEquals($answer, $givenAnswer); + $this->assertEquals( + 'foo'.\PHP_EOL. // write foo + \PHP_EOL.\PHP_EOL.\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL.\PHP_EOL. // question + 'bar'.\PHP_EOL. // write bar + "\033[10A\033[0J", // clear 10 lines (9 output lines and one from the answer input return) + stream_get_contents($output->getStream()) + ); + } } From a42df138c468dea73d342990d597c43a205b09fe Mon Sep 17 00:00:00 2001 From: Titouan Galopin Date: Fri, 9 Dec 2022 17:02:57 +0100 Subject: [PATCH 2/3] Fix missing command not matching namespace error message --- Application.php | 2 ++ Tests/ApplicationTest.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Application.php b/Application.php index 99548faf8..d4ec1be09 100644 --- a/Application.php +++ b/Application.php @@ -298,6 +298,8 @@ public function doRun(InputInterface $input, OutputInterface $output) return isset($event) ? $event->getExitCode() : 1; } + + throw $e; } catch (NamespaceNotFoundException) { throw $e; } diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index c17815168..c82c3eb18 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Console\Command\HelpCommand; use Symfony\Component\Console\Command\LazyCommand; use Symfony\Component\Console\Command\SignalableCommandInterface; +use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\Console\Event\ConsoleCommandEvent; @@ -1466,6 +1467,25 @@ public function testRunWithError() } } + public function testRunWithFindError() + { + $this->expectException(\Error::class); + $this->expectExceptionMessage('Find exception'); + + $application = new Application(); + $application->setAutoExit(false); + $application->setCatchExceptions(false); + + // Throws an exception when find fails + $commandLoader = $this->createMock(CommandLoaderInterface::class); + $commandLoader->method('getNames')->willThrowException(new \Error('Find exception')); + $application->setCommandLoader($commandLoader); + + // The exception should not be ignored + $tester = new ApplicationTester($application); + $tester->run(['command' => 'foo']); + } + public function testRunAllowsErrorListenersToSilenceTheException() { $dispatcher = $this->getDispatcher(); From c649f33ebddd3a2e2f49cb1f739c00506869c149 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Fri, 16 Dec 2022 15:44:15 +0100 Subject: [PATCH 3/3] Revert "bug #48089 [Console] Fix clear line with question in section (maxbeckers)" This reverts commit caffee8d62e7f998fcf6116ca128b8343017f3d2, reversing changes made to f14901e3a4343bb628ff0f7e5f213752381a069e. --- Output/ConsoleSectionOutput.php | 8 ------- Style/SymfonyStyle.php | 6 ------ Tests/Style/SymfonyStyleTest.php | 36 -------------------------------- 3 files changed, 50 deletions(-) diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index 527c1a224..d4c2f20c7 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -87,14 +87,6 @@ public function addContent(string $input) } } - /** - * @internal - */ - public function incrementLines() - { - ++$this->lines; - } - /** * {@inheritdoc} */ diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index 1de3b552f..f13c313d3 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -22,7 +22,6 @@ use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; -use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\TrimmedBufferOutput; use Symfony\Component\Console\Question\ChoiceQuestion; @@ -351,11 +350,6 @@ public function askQuestion(Question $question): mixed if ($this->input->isInteractive()) { $this->newLine(); $this->bufferedOutput->write("\n"); - if ($this->output instanceof ConsoleSectionOutput) { - // add one line more to the ConsoleSectionOutput because of the `return` to submit the input - // this is relevant when a `ConsoleSectionOutput::clear` is called. - $this->output->incrementLines(); - } } return $answer; diff --git a/Tests/Style/SymfonyStyleTest.php b/Tests/Style/SymfonyStyleTest.php index 3441449da..74c240340 100644 --- a/Tests/Style/SymfonyStyleTest.php +++ b/Tests/Style/SymfonyStyleTest.php @@ -16,13 +16,11 @@ use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Input\Input; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Tester\CommandTester; @@ -183,38 +181,4 @@ public function testMemoryConsumption() $this->assertSame(0, memory_get_usage() - $start); } - - public function testAskAndClearExpectFullSectionCleared() - { - $answer = 'Answer'; - $inputStream = fopen('php://memory', 'r+'); - fwrite($inputStream, $answer.\PHP_EOL); - rewind($inputStream); - $input = $this->createMock(Input::class); - $sections = []; - $output = new ConsoleSectionOutput(fopen('php://memory', 'r+', false), $sections, StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatter()); - $input - ->method('isInteractive') - ->willReturn(true); - $input - ->method('getStream') - ->willReturn($inputStream); - - $style = new SymfonyStyle($input, $output); - - $style->write('foo'); - $givenAnswer = $style->ask('Dummy question?'); - $output->write('bar'); - $output->clear(); - - rewind($output->getStream()); - $this->assertEquals($answer, $givenAnswer); - $this->assertEquals( - 'foo'.\PHP_EOL. // write foo - \PHP_EOL.\PHP_EOL.\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL.\PHP_EOL. // question - 'bar'.\PHP_EOL. // write bar - "\033[10A\033[0J", // clear 10 lines (9 output lines and one from the answer input return) - stream_get_contents($output->getStream()) - ); - } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy