Allow stdClass in XML responses

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/38745/head
jld3103 1 year ago
parent 39b716cc78
commit 7f4651637a
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3

@ -143,6 +143,10 @@ abstract class BaseResponse extends Response {
$k = 'element';
}
if ($v instanceof \stdClass) {
$v = [];
}
if (\is_array($v)) {
$writer->startElement($k);
$this->toXML($v, $writer);

@ -45,13 +45,14 @@ class BaseResponseTest extends \Test\TestCase {
'someElement' => 'withAttribute',
],
'value without key',
'object' => new \stdClass(),
];
$this->invokePrivate($response, 'toXml', [$data, $writer]);
$writer->endDocument();
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element>\n",
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n",
$writer->outputMemory(true)
);
}

Loading…
Cancel
Save