コード例 #1
0
ファイル: FileReportTest.php プロジェクト: sclable/xml-lint
 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
ファイル: LintValidation.php プロジェクト: sclable/xml-lint
 /**
  * @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();
 }