summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordi Boggiano <j.boggiano@seld.be>2017-06-19 03:08:32 +0200
committerJordi Boggiano <j.boggiano@seld.be>2017-06-19 03:09:14 +0200
commit69b21064ca55993d8083760af9b51a428e4edd6b (patch)
tree383237a2df5763aeebd36d536d626f87ab1cf325
parent443e4a94fc00711cb618b446d071b2a027395c88 (diff)
downloadmonolog-69b21064ca55993d8083760af9b51a428e4edd6b.zip
monolog-69b21064ca55993d8083760af9b51a428e4edd6b.tar.gz
monolog-69b21064ca55993d8083760af9b51a428e4edd6b.tar.bz2
Fix level map override when using setExceptionHandler, fixes #1005
-rw-r--r--src/Monolog/ErrorHandler.php7
-rw-r--r--tests/Monolog/ErrorHandlerTest.php24
2 files changed, 11 insertions, 20 deletions
diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php
index e4f0e83..d0b1aa6 100644
--- a/src/Monolog/ErrorHandler.php
+++ b/src/Monolog/ErrorHandler.php
@@ -77,7 +77,12 @@ class ErrorHandler
public function registerExceptionHandler($levelMap = [], $callPrevious = true): self
{
$prev = set_exception_handler([$this, 'handleException']);
- $this->uncaughtExceptionLevelMap = array_replace($this->defaultExceptionLevelMap(), $levelMap);
+ $this->uncaughtExceptionLevelMap = $levelMap;
+ foreach ($this->defaultExceptionLevelMap() as $class => $level) {
+ if (!isset($this->uncaughtExceptionLevelMap[$class])) {
+ $this->uncaughtExceptionLevelMap[$class] = $level;
+ }
+ }
if ($callPrevious && $prev) {
$this->previousExceptionHandler = $prev;
}
diff --git a/tests/Monolog/ErrorHandlerTest.php b/tests/Monolog/ErrorHandlerTest.php
index 0db0be9..9a8a5be 100644
--- a/tests/Monolog/ErrorHandlerTest.php
+++ b/tests/Monolog/ErrorHandlerTest.php
@@ -12,6 +12,7 @@
namespace Monolog;
use Monolog\Handler\TestHandler;
+use Psr\Log\LogLevel;
class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
{
@@ -82,27 +83,12 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
$logger = new Logger('test', [$handler = new TestHandler]);
$errHandler = new ErrorHandler($logger);
- $resHandler = $errHandler->registerExceptionHandler(['Monolog\CustomTestException' => Logger::ALERT, 'Throwable' => Logger::WARNING], false);
+ $resHandler = $errHandler->registerExceptionHandler($map = ['Monolog\CustomTestException' => LogLevel::DEBUG, 'TypeError' => LogLevel::NOTICE, 'Throwable' => LogLevel::WARNING], false);
$this->assertSame($errHandler, $resHandler);
- try {
- throw new CustomCustomException();
- $this->assertCount(1, $handler->getRecords());
- $this->assertTrue($handler->hasAlertRecords());
- } catch (\Throwable $e) {
- }
- try {
- throw new CustomTestException();
- $this->assertCount(2, $handler->getRecords());
- $this->assertTrue($handler->hasAlertRecords());
- } catch (\Throwable $e) {
- }
- try {
- throw new RuntimeException();
- $this->assertCount(3, $handler->getRecords());
- $this->assertTrue($handler->hasWarningRecords());
- } catch (\Throwable $e) {
- }
+ $map['ParseError'] = LogLevel::CRITICAL;
+ $prop = $this->getPrivatePropertyValue($errHandler, 'uncaughtExceptionLevelMap');
+ $this->assertSame($map, $prop);
$errHandler->registerExceptionHandler([], true);
$prop = $this->getPrivatePropertyValue($errHandler, 'previousExceptionHandler');