From 52db51c184ad7d98028ff4bb7b351fa34c7bd4b2 Mon Sep 17 00:00:00 2001 From: Bratstock Date: Tue, 11 Aug 2020 00:43:46 +0200 Subject: [PATCH 1/2] [Console] Display errors even when --quiet is present When using SymfonyStyle::error the message should be printed even when the --quiet option is used. --- .../Component/Console/Style/SymfonyStyle.php | 3 ++- .../Console/Tests/Style/SymfonyStyleTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 0d32763a0ff4f..1f161b3db4ff3 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -64,7 +64,8 @@ public function block($messages, ?string $type = null, ?string $style = null, st $messages = \is_array($messages) ? array_values($messages) : [$messages]; $this->autoPrependBlock(); - $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); + $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape), + self::OUTPUT_NORMAL|($type == 'ERROR' ? self::VERBOSITY_QUIET : 0)); $this->newLine(); } diff --git a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php index 943b94172a609..4f8dd458a0e2f 100644 --- a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php @@ -115,4 +115,24 @@ public function testGetErrorStyleUsesTheCurrentOutputIfNoErrorOutputIsAvailable( $this->assertInstanceOf(SymfonyStyle::class, $style->getErrorStyle()); } + + public function testPrintErrorIfWeRunInQuietMode() + { + $output = $this->getMockBuilder(OutputInterface::class)->getMock(); + $output + ->method('getFormatter') + ->willReturn(new OutputFormatter()); + $output + ->expects($this->once()) + ->method('writeln') + ->with( + $this->anything(), + $this->callback(function($type) + { + return (($type & OutputInterface::VERBOSITY_QUIET) == OutputInterface::VERBOSITY_QUIET) ? true:false; + } + )); + $style = new SymfonyStyle($this->getMockBuilder(InputInterface::class)->getMock(), $output); + $style->error('test'); + } } From 8e4dcc53f1e3df595166874a70284d006b604d8d Mon Sep 17 00:00:00 2001 From: Bratstock Date: Tue, 11 Aug 2020 01:33:54 +0200 Subject: [PATCH 2/2] changes from fabbot.io --- src/Symfony/Component/Console/Style/SymfonyStyle.php | 2 +- .../Component/Console/Tests/Style/SymfonyStyleTest.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 1f161b3db4ff3..a9c35931f37d9 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -65,7 +65,7 @@ public function block($messages, ?string $type = null, ?string $style = null, st $this->autoPrependBlock(); $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape), - self::OUTPUT_NORMAL|($type == 'ERROR' ? self::VERBOSITY_QUIET : 0)); + self::OUTPUT_NORMAL | ('ERROR' == $type ? self::VERBOSITY_QUIET : 0)); $this->newLine(); } diff --git a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php index 4f8dd458a0e2f..32adae1acf983 100644 --- a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php @@ -127,9 +127,8 @@ public function testPrintErrorIfWeRunInQuietMode() ->method('writeln') ->with( $this->anything(), - $this->callback(function($type) - { - return (($type & OutputInterface::VERBOSITY_QUIET) == OutputInterface::VERBOSITY_QUIET) ? true:false; + $this->callback(function ($type) { + return (OutputInterface::VERBOSITY_QUIET == ($type & OutputInterface::VERBOSITY_QUIET)) ? true : false; } )); $style = new SymfonyStyle($this->getMockBuilder(InputInterface::class)->getMock(), $output);