Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions 10 src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ public function getBubble(): bool

public function handle(LogRecord $record): bool
{
// we have to update the logging level each time because the verbosity of the
// console output might have changed in the meantime (it is not immutable)
return $this->updateLevel() && parent::handle($record);
if (!$this->isHandling($record)) {
return false;
}

parent::handle($record);

return !$this->getBubble();
}

public function setInput(InputInterface $input): void
Expand Down
41 changes: 41 additions & 0 deletions 41 src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Monolog\Tests\Handler;

use Monolog\Handler\TestHandler;
use Monolog\Level;
use Monolog\Logger;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -262,6 +263,46 @@ public function testInteractiveOnly()
self::assertTrue($handler->getBubble(), '->getBubble returns true when input is not interactive and interactiveOnly is true');
}

public function testInteractiveOnlyPreventsPropagationWhenInteractive()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails without the fix, proving that propogation isn't stopped, which contradicts the docs and I believe the intended behaviour.

Runtime:       PHP 8.2.31
Configuration: /home/runner/work/symfony/symfony/phpunit.xml

............................F.................................... 65 / 88 ( 73%)
.......................                                           88 / 88 (100%)

Time: 00:00.928, Memory: 24.00 MB

There was 1 failure:

1) Symfony\Bridge\Monolog\Tests\Handler\ConsoleHandlerTest::testInteractiveOnlyPreventsPropagationWhenInteractive
sibling handler must not receive records when interactive_only is true and input is interactive
Failed asserting that true is false.

/home/runner/work/symfony/symfony/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php:280
/home/runner/work/symfony/symfony/.phpunit/phpunit-11.5-0/phpunit:104
/home/runner/work/symfony/symfony/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php:458
/home/runner/work/symfony/symfony/vendor/symfony/phpunit-bridge/bin/simple-phpunit:13

FAILURES!
Tests: 88, Assertions: 238, Failures: 1.

{
$interactiveInput = $this->createStub(InputInterface::class);
$interactiveInput->method('isInteractive')->willReturn(true);

$consoleHandler = new ConsoleHandler(null, true, [], [], true);
$consoleHandler->setInput($interactiveInput);
$consoleHandler->setOutput(new BufferedOutput(OutputInterface::VERBOSITY_VERBOSE));

$sibling = new TestHandler();
$logger = new Logger('test', [$consoleHandler, $sibling]);

$logger->warning('hello');

self::assertFalse(
$sibling->hasWarningRecords(),
'sibling handler must not receive records when interactive_only is true and input is interactive',
);
}

public function testInteractiveOnlyAllowsPropagationWhenNotInteractive()
{
$nonInteractiveInput = $this->createStub(InputInterface::class);
$nonInteractiveInput->method('isInteractive')->willReturn(false);

$consoleHandler = new ConsoleHandler(null, true, [], [], true);
$consoleHandler->setInput($nonInteractiveInput);
$consoleHandler->setOutput(new BufferedOutput(OutputInterface::VERBOSITY_VERBOSE));

$sibling = new TestHandler();
$logger = new Logger('test', [$consoleHandler, $sibling]);

$logger->warning('hello');

self::assertTrue(
$sibling->hasWarningRecords(),
'sibling handler must still receive records when interactive_only is true but input is not interactive',
);
}

public function testNestedCommandsDoNotCloseHandler()
{
$output = new BufferedOutput();
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.