예제 #1
0
 public function testHasProblemsReturnsTrueOnProblems()
 {
     $report = new FileReport(new \SplFileInfo('no_file.xml'));
     $problem = $this->getMockBuilder(ValidationProblem::class)->disableOriginalConstructor()->getMock();
     /** @var ValidationProblem $problem */
     $report->addProblem($problem);
     $this->assertTrue($report->hasProblems());
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function validateFile(FileReport $report)
 {
     $realPath = $report->getFile()->getRealPath();
     if (is_file($realPath) === false) {
         $report->reportProblem('file not found: ' . $realPath);
         return false;
     }
     if (is_readable($realPath) === false) {
         $report->reportProblem('file not readable: ' . $realPath);
         return false;
     }
     libxml_clear_errors();
     $domDoc = new \DOMDocument();
     $domDoc->load($realPath, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_PEDANTIC);
     $errors = libxml_get_errors();
     foreach ($this->formatter->formatErrors($errors) as $problem) {
         $report->reportProblem($problem);
     }
     return !$report->hasProblems();
 }