hi foo foo & bar BLA; $reader = new Reader(); $reader->elementMap = [ '{http://sabredav.org/ns}struct' => function(Reader $reader) { return keyValue($reader, 'http://sabredav.org/ns'); } ]; $reader->xml($input); $output = $reader->parse(); $this->assertEquals([ 'name' => '{http://sabredav.org/ns}root', 'value' => [ [ 'name' => '{http://sabredav.org/ns}struct', 'value' => [ 'elem1' => null, 'elem2' => 'hi', '{http://sabredav.org/another-ns}elem3' => [ [ 'name' => '{http://sabredav.org/another-ns}elem4', 'value' => 'foo', 'attributes' => [], ], [ 'name' => '{http://sabredav.org/another-ns}elem5', 'value' => 'foo & bar', 'attributes' => [], ], ], 'elem6' => null, ], 'attributes' => [], ] ], 'attributes' => [], ], $output); } /** * @expectedException \Sabre\Xml\LibXMLException */ function testKeyValueLoop() { /** * This bug is a weird one, because it triggers an infinite loop, but * only if the XML document is a certain size (in bytes). Removing one * or two characters from the xml body here cause the infinite loop to * *not* get triggered, so to properly test this bug (Issue #94), don't * change the XML body. */ $invalid_xml = ' NONE ENVELOPE 1 DC NONE ENVELOPE 1 DC/FleetType> '; $reader = new Reader(); $reader->xml($invalid_xml); $reader->elementMap = [ '{}Package' => function($reader) { $recipient = []; // Borrowing a parser from the KeyValue class. $keyValue = keyValue($reader); if (isset($keyValue['{}WeightOz'])){ $recipient['referenceId'] = $keyValue['{}WeightOz']; } return $recipient; }, ]; $reader->parse(); } function testEmptyKeyValue() { // the nested structure below is necessary to detect if one of the deserialization functions eats to much elements $input = << BLA; $reader = new Reader(); $reader->elementMap = [ '{http://sabredav.org/ns}struct' => function(Reader $reader) { return keyValue($reader, 'http://sabredav.org/ns'); }, ]; $reader->xml($input); $output = $reader->parse(); $this->assertEquals([ 'name' => '{http://sabredav.org/ns}root', 'value' => [ [ 'name' => '{http://sabredav.org/ns}inner', 'value' => [ [ 'name' => '{http://sabredav.org/ns}struct', 'value' => [], 'attributes' => [], ], ], 'attributes' => [], ], ], 'attributes' => [], ], $output); } }