8000 [Serializer][XmlEncoder] Allow removing empty tags in generated XML by amoiraud · Pull Request #20524 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer][XmlEncoder] Allow removing empty tags in generated XML #20524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case to remove empty tags
  • Loading branch information
amoiraud committed Nov 14, 2016
commit b83afacb9da01cf468d9c310e4f6d5a8a12c4aa1
15 changes: 15 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ public function testEncodeXmlAttributes()
$this->assertSame($expected, $this->encoder->encode($array, 'xml', $context));
}

public function testEncodeRemovingEmptyTags()
{
$xml = simplexml_load_string('<firstname>Peter</firstname><lastname/>');
$array = array('person' => $xml);

$expected = '<?xml version="1.0"?>'."\n".
'<response><person><firstname>Peter</firstname></person></response>'."\n";

$context = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be inline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right i have made the modification

'remove_empty_tags' => true
);

$this->assertSame($expected, $this->encoder->encode($array, 'xml', $context));
}

public function testContext()
{
$array = array('person' => array('name' => 'George Abitbol'));
Expand Down
0