Harry
Turtle
XML;
$reader = new Reader();
$reader->xml($input);
$reader->elementMap = [
'{urn:foo}foo' => function(Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
}
];
$output = $reader->parse();
$vo = new TestVo();
$vo->firstName = 'Harry';
$vo->lastName = 'Turtle';
$expected = [
'name' => '{urn:foo}foo',
'value' => $vo,
'attributes' => []
];
$this->assertEquals(
$expected,
$output
);
}
function testDeserializeValueObjectIgnoredElement() {
$input = <<
Harry
Turtle
harry@example.org
XML;
$reader = new Reader();
$reader->xml($input);
$reader->elementMap = [
'{urn:foo}foo' => function(Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
}
];
$output = $reader->parse();
$vo = new TestVo();
$vo->firstName = 'Harry';
$vo->lastName = 'Turtle';
$expected = [
'name' => '{urn:foo}foo',
'value' => $vo,
'attributes' => []
];
$this->assertEquals(
$expected,
$output
);
}
function testDeserializeValueObjectAutoArray() {
$input = <<
Harry
Turtle
http://example.org/
http://example.net/
XML;
$reader = new Reader();
$reader->xml($input);
$reader->elementMap = [
'{urn:foo}foo' => function(Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
}
];
$output = $reader->parse();
$vo = new TestVo();
$vo->firstName = 'Harry';
$vo->lastName = 'Turtle';
$vo->link = [
'http://example.org/',
'http://example.net/',
];
$expected = [
'name' => '{urn:foo}foo',
'value' => $vo,
'attributes' => []
];
$this->assertEquals(
$expected,
$output
);
}
function testDeserializeValueObjectEmpty() {
$input = <<
XML;
$reader = new Reader();
$reader->xml($input);
$reader->elementMap = [
'{urn:foo}foo' => function(Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
}
];
$output = $reader->parse();
$vo = new TestVo();
$expected = [
'name' => '{urn:foo}foo',
'value' => $vo,
'attributes' => []
];
$this->assertEquals(
$expected,
$output
);
}
}
class TestVo {
public $firstName;
public $lastName;
public $link = [];
}