From 9ce043119106fe2d7aa16000791a4992e7321863 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 10 Dec 2020 16:22:14 +0100 Subject: [PATCH] Add JSON_PARTIAL_OUTPUT_ON_ERROR, closes #1515 --- src/Monolog/Utils.php | 2 +- .../Formatter/NormalizerFormatterTest.php | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index 41e24031..9f906a3b 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -13,7 +13,7 @@ namespace Monolog; final class Utils { - const DEFAULT_JSON_FLAGS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_SUBSTITUTE; + const DEFAULT_JSON_FLAGS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR; public static function getClass(object $object): string { diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index 90dd835f..00cc1fb9 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -208,11 +208,7 @@ class NormalizerFormatterTest extends TestCase restore_error_handler(); - if (PHP_VERSION_ID < 50500) { - $this->assertEquals('[{"bar":{"foo":null}},{"foo":{"bar":null}}]', $res); - } else { - $this->assertEquals('null', $res); - } + $this->assertEquals('[{"bar":{"foo":null}},{"foo":{"bar":null}}]', $res); } public function testCanNormalizeReferences() @@ -224,9 +220,9 @@ class NormalizerFormatterTest extends TestCase $formatter->format($y); } - public function testIgnoresInvalidTypes() + public function testToJsonIgnoresInvalidTypes() { - // set up the recursion + // set up the invalid data $resource = fopen(__FILE__, 'r'); // set an error handler to assert that the error is not raised anymore @@ -247,11 +243,7 @@ class NormalizerFormatterTest extends TestCase restore_error_handler(); - if (PHP_VERSION_ID < 50500) { - $this->assertEquals('[null]', $res); - } else { - $this->assertEquals('null', $res); - } + $this->assertEquals('[null]', $res); } public function testNormalizeHandleLargeArraysWithExactly1000Items()