/** * @covers W3C\Formatter\Checkstyle::format */ public function testFormatAddsWarningViolations() { $formatter = $this->getMock('W3C\\Formatter\\Checkstyle', array('addViolation')); $result = new Result(); $warning1 = new Violation(); $warning2 = new Violation(); $result->addWarning($warning1)->addWarning($warning2); $formatter->expects($this->at(0))->method('addViolation')->with($this->anything(), $this->identicalTo($warning1), 'warning'); $formatter->expects($this->at(1))->method('addViolation')->with($this->anything(), $this->identicalTo($warning2), 'warning'); $formatter->format($result); }
/** * Formats a result object as a checkstyle report xml and returns the xml content. * * @param Result $result The result object for which the xml report should be created * @param string|null $url (optional) URL of the page, will be added to the <file> tag * @return string XML in checkstyle format */ public function format(Result $result, $url = null) { $xml = new SimpleXMLElement('<checkstyle />'); $file = $xml->addChild('file'); if ($url) { $file->addAttribute('name', $url); } $errors = $result->getErrors(); $warnings = $result->getWarnings(); foreach ($errors as $error) { $this->addViolation($file, $error, 'error'); } foreach ($warnings as $warning) { $this->addViolation($file, $warning, 'warning'); } return $xml->asXML(); }
/** * Parses the SOAP response of the API and returns a new Result object. * * @param string $response SOAP response of the API * @return Result */ protected function parseResponse($response) { $xml = new SimpleXMLElement($response); $ns = $xml->getNamespaces(true); $data = $xml->children($ns['env'])->children($ns['m'])->markupvalidationresponse; $result = new Result(); $result->setIsValid($data->validity == 'true'); foreach ($data->errors->errorlist->error as $error) { $entry = $this->getEntry($error); $result->addError($entry); } foreach ($data->warnings->warninglist->warning as $warning) { if (strpos($warning->messageid, 'W') === false) { $entry = $this->getEntry($warning); $result->addWarning($entry); } } return $result; }