glaszig/snippets — pull request #1 by pschultz (2012-04-23 14:02:00+00:00)
Title: fixing unset after first echo

`unset($xml->foo->bar);` is broken after first echo because the DOMDocument tree isn't updated along with `$this->children`. This pull request fixes this.

PHPUnit test case to verify this:

element->formatOutput = false;
}
}

class XmlBuilderTest extends PHPUnit_Framework_TestCase {

// passes
public function testUnset() {
$xml = new TestXmlBuilder();
$xml->foo->bar = 'baz';

unset($xml->foo->bar);
$this->expectXml("");

echo $xml;
}

// fails
public function testUnsetAfterEcho() {
$xml = new TestXmlBuilder();
$xml->foo->bar = 'baz';

ob_start();
echo $xml;
ob_end_clean();

unset($xml->foo->bar);
$this->expectXml("");

echo $xml;
}

private function expectXml($xml) {
$this->expectOutputString("\n$xml\n");
}
}