saloonphp / xml-wrangler

🌵 XML Wrangler - Easily Read & Write XML in PHP
MIT License
360 stars 14 forks source link

comment tag is missing #28

Open aliaswpeu opened 4 months ago

aliaswpeu commented 4 months ago

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
"""
Sammyjo20 commented 2 months ago

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?

aliaswpeu commented 2 months ago

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.

Sammyjo20 commented 2 months ago

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.