bar XML; $expected = [ '{DAV:}foo' => 'bar', ]; $this->assertDecodeProp($input, $expected); } function testDeserializeEmpty() { $input = << XML; $expected = [ ]; $this->assertDecodeProp($input, $expected); } function testDeserializeComplex() { $input = << yes XML; $expected = [ '{DAV:}foo' => new Complex('yes') ]; $this->assertDecodeProp($input, $expected); } function testDeserializeCustom() { $input = << /hello XML; $expected = [ '{DAV:}foo' => new Href('/hello', false) ]; $elementMap = [ '{DAV:}foo' => 'Sabre\DAV\Xml\Property\Href' ]; $this->assertDecodeProp($input, $expected, $elementMap); } function testDeserializeCustomCallback() { $input = << blabla XML; $expected = [ '{DAV:}foo' => 'zim', ]; $elementMap = [ '{DAV:}foo' => function($reader) { $reader->next(); return 'zim'; } ]; $this->assertDecodeProp($input, $expected, $elementMap); } /** * @expectedException \LogicException */ function testDeserializeCustomBad() { $input = << blabla XML; $expected = []; $elementMap = [ '{DAV:}foo' => 'idk?', ]; $this->assertDecodeProp($input, $expected, $elementMap); } /** * @expectedException \LogicException */ function testDeserializeCustomBadObj() { $input = << blabla XML; $expected = []; $elementMap = [ '{DAV:}foo' => new \StdClass(), ]; $this->assertDecodeProp($input, $expected, $elementMap); } function assertDecodeProp($input, array $expected, array $elementMap = []) { $elementMap['{DAV:}root'] = 'Sabre\DAV\Xml\Element\Prop'; $result = $this->parse($input, $elementMap); $this->assertInternalType('array', $result); $this->assertEquals($expected, $result['value']); } }