Skip to content
Permalink
Browse files

Avoid leaving an error handler dangling

  • Loading branch information
Seldaek committed Sep 5, 2019
1 parent 40cce3b commit 0f39561898a66334fe5f2a6768eb8043d2f34cd5
Showing with 20 additions and 12 deletions.
  1. +20 −12 tests/Monolog/ErrorHandlerTest.php
@@ -28,18 +28,26 @@ public function testHandleError()
$logger = new Logger('test', [$handler = new TestHandler]);
$errHandler = new ErrorHandler($logger);

$resHandler = $errHandler->registerErrorHandler([E_USER_NOTICE => Logger::EMERGENCY], false);
$this->assertSame($errHandler, $resHandler);
trigger_error('Foo', E_USER_ERROR);
$this->assertCount(1, $handler->getRecords());
$this->assertTrue($handler->hasErrorRecords());
trigger_error('Foo', E_USER_NOTICE);
$this->assertCount(2, $handler->getRecords());
$this->assertTrue($handler->hasEmergencyRecords());

$errHandler->registerErrorHandler([], true);
$prop = $this->getPrivatePropertyValue($errHandler, 'previousErrorHandler');
$this->assertTrue(is_callable($prop));
$phpunitHandler = set_error_handler($prevHandler = function() {});

try {
$errHandler->registerErrorHandler([], true);
$prop = $this->getPrivatePropertyValue($errHandler, 'previousErrorHandler');
$this->assertTrue(is_callable($prop));
$this->assertSame($prevHandler, $prop);

$resHandler = $errHandler->registerErrorHandler([E_USER_NOTICE => Logger::EMERGENCY], false);
$this->assertSame($errHandler, $resHandler);
trigger_error('Foo', E_USER_ERROR);
$this->assertCount(1, $handler->getRecords());
$this->assertTrue($handler->hasErrorRecords());
trigger_error('Foo', E_USER_NOTICE);
$this->assertCount(2, $handler->getRecords());
$this->assertTrue($handler->hasEmergencyRecords());
} finally {
// restore previous handler
set_error_handler($phpunitHandler);
}
}

public function fatalHandlerProvider()

0 comments on commit 0f39561

Please sign in to comment.
You can’t perform that action at this time.