/** * Assert a specific set of violations. * * @param File $file * @param array $expectedViolations * @return void */ public function assertRuleViolations(File $file, array $expectedViolations) { // Get all violations and convert them to an array for comparision. $violations = array(); foreach ($file->getViolations() as $error) { $violations[] = array('line' => $error->getLine(), 'column' => $error->getColumn(), 'message' => $error->getMessage(), 'source' => $error->getSource()); } $this->assertEquals($expectedViolations, $violations); }
/** * addFile(): defined by Report interface. * * @see Report::addFile() * @param File $file * @return void */ public function addFile(File $file) { $this->writer->startElement('file'); $this->writer->writeAttribute('name', $file->getFilename()); foreach ($file->getViolations() as $violation) { $this->writer->startElement('error'); $this->writer->writeAttribute('line', $violation->getLine()); if ($violation->getColumn() > 0) { $this->writer->writeAttribute('column', $violation->getColumn()); } $this->writer->writeAttribute('severity', $violation->getSeverity()); $this->writer->writeAttribute('message', $violation->getMessage()); $this->writer->writeAttribute('source', $violation->getSource()); $this->writer->endElement(); } $this->writer->endElement(); }
/** * addFile(): defined by Report interface. * * @see Report::addFile() * @param File $file * @return void */ public function addFile(File $file) { $violations = $file->getViolations(); if ($violations) { if ($this->firstFile) { $this->firstFile = false; } else { echo PHP_EOL; } echo $file->getFilename() . ':' . PHP_EOL; echo str_repeat('-', 80) . PHP_EOL; foreach ($violations as $violation) { echo $violation->getLine() . ':'; if ($violation->getColumn() > 0) { echo $violation->getColumn() . ':'; } echo $violation->getSeverityName() . ': '; echo $violation->getMessage() . PHP_EOL; } flush(); } }