[Serializer] Fix that it will never reach DOMNode
This commit is contained in:
parent
cc827466bb
commit
38787ac785
@ -488,6 +488,9 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
$node->appendChild($child);
|
$node->appendChild($child);
|
||||||
} elseif ($val instanceof \Traversable) {
|
} elseif ($val instanceof \Traversable) {
|
||||||
$this->buildXml($node, $val);
|
$this->buildXml($node, $val);
|
||||||
|
} elseif ($val instanceof \DOMNode) {
|
||||||
|
$child = $this->dom->importNode($val, true);
|
||||||
|
$node->appendChild($child);
|
||||||
} elseif (\is_object($val)) {
|
} elseif (\is_object($val)) {
|
||||||
if (null === $this->serializer) {
|
if (null === $this->serializer) {
|
||||||
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
|
||||||
@ -502,9 +505,6 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
return $this->appendText($node, $val);
|
return $this->appendText($node, $val);
|
||||||
} elseif (\is_bool($val)) {
|
} elseif (\is_bool($val)) {
|
||||||
return $this->appendText($node, (int) $val);
|
return $this->appendText($node, (int) $val);
|
||||||
} elseif ($val instanceof \DOMNode) {
|
|
||||||
$child = $this->dom->importNode($val, true);
|
|
||||||
$node->appendChild($child);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -662,6 +662,20 @@ XML;
|
|||||||
$this->assertEquals($expectedXml, $actualXml);
|
$this->assertEquals($expectedXml, $actualXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEncodeXmlWithDomNodeValue()
|
||||||
|
{
|
||||||
|
$expectedXml = <<<'XML'
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<response><foo>bar</foo><bar>foo & bar</bar></response>
|
||||||
|
|
||||||
|
XML;
|
||||||
|
$document = new \DOMDocument();
|
||||||
|
|
||||||
|
$actualXml = $this->encoder->encode(['foo' => $document->createTextNode('bar'), 'bar' => $document->createTextNode('foo & bar')], 'xml');
|
||||||
|
|
||||||
|
$this->assertEquals($expectedXml, $actualXml);
|
||||||
|
}
|
||||||
|
|
||||||
public function testEncodeXmlWithDateTimeObjectValue()
|
public function testEncodeXmlWithDateTimeObjectValue()
|
||||||
{
|
{
|
||||||
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
||||||
|
Reference in New Issue
Block a user