/** * Test proper formatting of errors/warnings * * @covers HtmlValidator\Response::__construct * @covers HtmlValidator\Response::validateResponse * @covers HtmlValidator\Response::parse * @covers HtmlValidator\Response::format * @covers HtmlValidator\Response::__toString * @covers HtmlValidator\Response::toHTML */ public function testWillFormat() { $data = array('messages' => array(array('type' => 'warning', 'firstLine' => 1, 'lastLine' => 2, 'firstColumn' => 3, 'lastColumn' => 4, 'hiliteStart' => 5, 'hiliteLength' => 6, 'message' => 'Foobar', 'extract' => '<strong>Foo</strong>'), array('type' => 'error', 'firstLine' => 9, 'lastLine' => 8, 'firstColumn' => 7, 'lastColumn' => 6, 'hiliteStart' => 9, 'hiliteLength' => 7, 'message' => 'Pimp Pelican', 'extract' => '<em>Pimp Pelican</em>'))); $responseMock = $this->getGuzzleResponseMock(true); $responseMock->expects($this->any())->method('getBody')->will($this->returnValue(json_encode($data))); $response = new Response($responseMock); // Plain text $expected = 'warning: Foobar' . PHP_EOL; $expected .= 'From line 1, column 3; to line 2, column 4' . PHP_EOL; $expected .= '<strong>Foo</strong>' . PHP_EOL . PHP_EOL; $expected .= 'error: Pimp Pelican' . PHP_EOL; $expected .= 'From line 9, column 7; to line 8, column 6' . PHP_EOL; $expected .= '<em>Pimp Pelican</em>'; $this->assertSame($expected, (string) $response); // HTML $expected = '<strong>warning</strong>: Foobar<br>' . PHP_EOL; $expected .= 'From line 1, column 3; to line 2, column 4<br>' . PHP_EOL; $expected .= '<stro<span class="highlight">ng>Foo</span></strong>' . PHP_EOL . PHP_EOL; $expected .= '<strong>error</strong>: Pimp Pelican<br>' . PHP_EOL; $expected .= 'From line 9, column 7; to line 8, column 6<br>' . PHP_EOL; $expected .= '<em>Pimp <span class="highlight">Pelican</span></em>'; $this->assertSame($expected, $response->toHTML()); }