Просмотр исходного кода

Add JSON_PARTIAL_OUTPUT_ON_ERROR, closes #1515

Jordi Boggiano 5 лет назад
Родитель
Сommit
9ce0431191
2 измененных файлов с 5 добавлено и 13 удалено
  1. 1 1
      src/Monolog/Utils.php
  2. 4 12
      tests/Monolog/Formatter/NormalizerFormatterTest.php

+ 1 - 1
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
     {

+ 4 - 12
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()