Ver código fonte

Fix SoapFault when detail is nested object, fixes #1431, refs #1462

Jordi Boggiano 5 anos atrás
pai
commit
acd3173c4a

+ 6 - 2
src/Monolog/Formatter/NormalizerFormatter.php

@@ -142,8 +142,12 @@ class NormalizerFormatter implements FormatterInterface
                 $data['faultactor'] = $e->faultactor;
             }
 
-            if (isset($e->detail) && (is_string($e->detail) || is_object($e->detail) || is_array($e->detail))) {
-                $data['detail'] = is_string($e->detail) ? $e->detail : reset($e->detail);
+            if (isset($e->detail)) {
+                if  (is_string($e->detail)) {
+                    $data['detail'] = $e->detail;
+                } elseif (is_object($e->detail) || is_array($e->detail)) {
+                    $data['detail'] = $this->toJson($e->detail, true);
+                }
             }
         }
 

+ 21 - 1
tests/Monolog/Formatter/NormalizerFormatterTest.php

@@ -92,7 +92,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
         }
 
         $formatter = new NormalizerFormatter('Y-m-d');
-        $e = new \SoapFault('foo', 'bar', 'hello', (object) array('foo' => 'world'));
+        $e = new \SoapFault('foo', 'bar', 'hello', 'world');
         $formatted = $formatter->format(array(
             'exception' => $e,
         ));
@@ -110,6 +110,26 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
                 'detail' => 'world',
             ),
         ), $formatted);
+
+        $formatter = new NormalizerFormatter('Y-m-d');
+        $e = new \SoapFault('foo', 'bar', 'hello', (object) ['bar' => (object) ['biz' => 'baz'], 'foo' => 'world']);
+        $formatted = $formatter->format([
+            'exception' => $e,
+        ]);
+
+        unset($formatted['exception']['trace']);
+
+        $this->assertEquals([
+            'exception' => [
+                'class' => 'SoapFault',
+                'message' => 'bar',
+                'code' => 0,
+                'file' => $e->getFile().':'.$e->getLine(),
+                'faultcode' => 'foo',
+                'faultactor' => 'hello',
+                'detail' => '{"bar":{"biz":"baz"},"foo":"world"}',
+            ],
+        ], $formatted);
     }
 
     public function testFormatToStringExceptionHandle()