public function testCustomFormatError() { $errors = [$this->createLibXmlError('test', 1, 2)]; $formatter = new LibXmlErrorFormatter(); $formatter->setFormat('%s / %s / %s'); $this->assertEquals(['2 / 1 / test'], $formatter->formatErrors($errors)); }
/** * @inheritDoc */ public function validateFile(FileReport $report) { $file = $report->getFile()->getRealPath(); if (empty($file)) { return false; } $domDoc = new \DOMDocument(); $loaded = $domDoc->load($file, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_PEDANTIC); if ($loaded === false) { return false; } $validation = $this->getSchemaValidationFile($domDoc); if ($validation === false) { return true; } $validationSource = $this->getSchemaValidationSource($validation, $report); if ($validationSource === false) { return false; } libxml_clear_errors(); if ($domDoc->schemaValidateSource($validationSource) !== true) { $errors = libxml_get_errors(); foreach ($this->formatter->formatErrors($errors) as $problem) { $report->reportProblem($problem); } return false; } return true; }
/** * @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(); }