/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.xml'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); $this->linter->setLoadFromNet($config['load_from_net']); $this->linter->setXInclude($config['x_include']); $this->linter->setDtdValidation($config['dtd_validation']); $this->linter->setSchemeValidation($config['scheme_validation']); $lintErrors = $this->lint($files); if ($lintErrors->count()) { throw new RuntimeException($lintErrors->__toString()); } }
function it_throws_exception_if_the_process_fails(XmlLinter $linter, ContextInterface $context) { $linter->isInstalled()->willReturn(true); $linter->setLoadFromNet(false)->shouldBeCalled(); $linter->setXInclude(false)->shouldBeCalled(); $linter->setDtdValidation(false)->shouldBeCalled(); $linter->setSchemeValidation(false)->shouldBeCalled(); $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new XmlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.xml', 1, 1)))); $context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.xml', '.', 'file.xml')))); $this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $this->linter->setLoadFromNet($config['load_from_net']); $this->linter->setXInclude($config['x_include']); $this->linter->setDtdValidation($config['dtd_validation']); $this->linter->setSchemeValidation($config['scheme_validation']); try { $lintErrors = $this->lint($files); } catch (RuntimeException $e) { return TaskResult::createFailed($this, $context, $e->getMessage()); } if ($lintErrors->count()) { return TaskResult::createFailed($this, $context, (string) $lintErrors); } return TaskResult::createPassed($this, $context); }
function it_throws_exception_if_the_process_fails(XmlLinter $linter, ContextInterface $context) { $linter->isInstalled()->willReturn(true); $linter->setLoadFromNet(false)->shouldBeCalled(); $linter->setXInclude(false)->shouldBeCalled(); $linter->setDtdValidation(false)->shouldBeCalled(); $linter->setSchemeValidation(false)->shouldBeCalled(); $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection([new XmlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.xml', 1, 1)])); $context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file.xml', '.', 'file.xml')])); $result = $this->run($context); $result->shouldBeAnInstanceOf(TaskResultInterface::class); $result->isPassed()->shouldBe(false); }
/** * @test * @dataProvider provideSchemeValidation */ function it_should_validate_xml_with_xsd($fixture, $errors, $loadFromNet) { $this->linter->setSchemeValidation(true); $this->linter->setLoadFromNet($loadFromNet); $this->validateFixture($fixture, $errors); }