Skip to content

Commit acd3173

Browse files
committed
Fix SoapFault when detail is nested object, fixes #1431, refs #1462
1 parent 74f92ea commit acd3173

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/Monolog/Formatter/NormalizerFormatter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ protected function normalizeException($e)
142142
$data['faultactor'] = $e->faultactor;
143143
}
144144

145-
if (isset($e->detail) && (is_string($e->detail) || is_object($e->detail) || is_array($e->detail))) {
146-
$data['detail'] = is_string($e->detail) ? $e->detail : reset($e->detail);
145+
if (isset($e->detail)) {
146+
if (is_string($e->detail)) {
147+
$data['detail'] = $e->detail;
148+
} elseif (is_object($e->detail) || is_array($e->detail)) {
149+
$data['detail'] = $this->toJson($e->detail, true);
150+
}
147151
}
148152
}
149153

tests/Monolog/Formatter/NormalizerFormatterTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testFormatSoapFaultException()
9292
}
9393

9494
$formatter = new NormalizerFormatter('Y-m-d');
95-
$e = new \SoapFault('foo', 'bar', 'hello', (object) array('foo' => 'world'));
95+
$e = new \SoapFault('foo', 'bar', 'hello', 'world');
9696
$formatted = $formatter->format(array(
9797
'exception' => $e,
9898
));
@@ -110,6 +110,26 @@ public function testFormatSoapFaultException()
110110
'detail' => 'world',
111111
),
112112
), $formatted);
113+
114+
$formatter = new NormalizerFormatter('Y-m-d');
115+
$e = new \SoapFault('foo', 'bar', 'hello', (object) ['bar' => (object) ['biz' => 'baz'], 'foo' => 'world']);
116+
$formatted = $formatter->format([
117+
'exception' => $e,
118+
]);
119+
120+
unset($formatted['exception']['trace']);
121+
122+
$this->assertEquals([
123+
'exception' => [
124+
'class' => 'SoapFault',
125+
'message' => 'bar',
126+
'code' => 0,
127+
'file' => $e->getFile().':'.$e->getLine(),
128+
'faultcode' => 'foo',
129+
'faultactor' => 'hello',
130+
'detail' => '{"bar":{"biz":"baz"},"foo":"world"}',
131+
],
132+
], $formatted);
113133
}
114134

115135
public function testFormatToStringExceptionHandle()

0 commit comments

Comments
 (0)