* @since 2.0
*
* @group web
*/
class XmlResponseFormatterTest extends FormatterTest
{
/**
* @return XmlResponseFormatter
*/
protected function getFormatterInstance()
{
return new XmlResponseFormatter();
}
private $xmlHead = "\n";
private function addXmlHead(array $data)
{
foreach ($data as &$item) {
$item[1] = $this->xmlHead . $item[1];
}
return $data;
}
public function formatScalarDataProvider()
{
return $this->addXmlHead([
[1, "1\n"],
['abc', "abc\n"],
[true, "1\n"],
["<>", "<>\n"],
]);
}
public function formatArrayDataProvider()
{
return $this->addXmlHead([
[[], "\n"],
[[1, 'abc'], "- 1
- abc
\n"],
[[
'a' => 1,
'b' => 'abc',
], "1abc\n"],
[[
1,
'abc',
[2, 'def'],
true,
], "- 1
- abc
- 2
- def
- 1
\n"],
[[
'a' => 1,
'b' => 'abc',
'c' => [2, '<>'],
true,
], "1abc- 2
- <>
- 1
\n"],
]);
}
public function formatObjectDataProvider()
{
return $this->addXmlHead([
[new Post(123, 'abc'), "123abc\n"],
[[
new Post(123, 'abc'),
new Post(456, 'def'),
], "123abc456def\n"],
[[
new Post(123, '<>'),
'a' => new Post(456, 'def'),
], "123<>456def\n"],
]);
}
}