xml-wrangler icon indicating copy to clipboard operation
xml-wrangler copied to clipboard

comment tag is missing

Open aliaswpeu opened this issue 1 year ago • 3 comments

Hello, when using like this, comment tag is not rendered:

$order_body = XmlWriter::make()
            ->setXmlStandalone(true)
            ->write('orders', [
                'order' => [
                    'cod' => '123',
                    'comment' => 'test comment',
                ],

            ]);
"""
<?xml version="1.0" encoding="utf-8"?>\n
<orders>\n
  <order>\n
    <cod>123</cod>\n
    test comment\n
  </order>\n
</orders>\n
"""

Should be:

"""
<?xml version="1.0" encoding="utf-8"?>\n
<orders>\n
  <order>\n
    <cod>123</cod>\n
    <comment>test comment</comment>\n
  </order>\n
</orders>\n
"""

aliaswpeu avatar Jun 29 '24 08:06 aliaswpeu

This is a very very strange one, I wrote a test to replicate this issue and the XML string that XML Wrangler created looked correct, however when I tried to add an assertion, PEST was magically removing the <comment> tag.

Screenshot 2024-08-03 at 14 42 52

I managed to "fix" the test by putting the expected XML into a variable instead of directly referencing it inside of the toBe expectation.

I don't think there is a bug with XML Wrangler here, as it did produce the expected outcome, but I would check your test suite. Do you have any more information you could share?

Sammyjo20 avatar Aug 03 '24 13:08 Sammyjo20

I was just dumping my output to terminal to see if it is correct. While I was searching why it happened, if I remember correctly, it was something in veewee/xml package. But I did not manage to fix it. For now, just skipping the comment section in output.

aliaswpeu avatar Aug 03 '24 15:08 aliaswpeu

I believe the writer uses spatie/array-to-xml and veewee/xml is solely used for reading. Still a very strange issue, because my direct output showed it looked fine, but PEST had the wrong output.

Sammyjo20 avatar Aug 03 '24 22:08 Sammyjo20