public format ( |
||
$response | the response to be formatted. |
public function format($response)
{
$charset = $this->encoding === null ? $response->charset : $this->encoding;
if (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
if ($response->data !== null) {
$dom = new DOMDocument($this->version, $charset);
$root = new DOMElement($this->rootTag);
$dom->appendChild($root);
$this->buildXml($root, $response->data);
$response->content = $dom->saveXML();
}
}
/** * @param mixed $data the data to be formatted * @param string $xml the expected XML body * @dataProvider formatObjectDataProvider */ public function testFormatObjects($data, $xml) { $head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $this->response->data = $data; $this->formatter->format($this->response); $this->assertEquals($head . $xml, $this->response->content); }