/** * @test */ function it_should_handle_exceptions_on_invalid_type() { $this->linter->setObjectSupport(false); $this->linter->setExceptionOnInvalidType(true); $fixture = YamlLinter::supportsFlags() ? 'object-support.yml' : 'object-support-old.yml'; $this->validateFixture($fixture, 1); }
function it_throws_exception_if_the_process_fails(YamlLinter $linter, ContextInterface $context) { $linter->isInstalled()->willReturn(true); $linter->setObjectSupport(false)->shouldBeCalled(); $linter->setExceptionOnInvalidType(false)->shouldBeCalled(); $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new YamlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.yaml', 1, 1)))); $context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.yaml', '.', 'file.yaml')))); $this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context); }
function it_throws_exception_if_the_process_fails(YamlLinter $linter, ContextInterface $context) { $linter->isInstalled()->willReturn(true); $linter->setObjectSupport(false)->shouldBeCalled(); $linter->setExceptionOnInvalidType(false)->shouldBeCalled(); $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection([new YamlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.yaml', 1, 1)])); $context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file.yaml', '.', 'file.yaml')])); $result = $this->run($context); $result->shouldBeAnInstanceOf(TaskResultInterface::class); $result->isPassed()->shouldBe(false); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('/\\.(yaml|yml)$/i'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); $this->linter->setObjectSupport($config['object_support']); $this->linter->setExceptionOnInvalidType($config['exception_on_invalid_type']); $lintErrors = $this->lint($files); if ($lintErrors->count()) { throw new RuntimeException($lintErrors->__toString()); } }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('/\\.(yaml|yml)$/i'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $this->linter->setObjectSupport($config['object_support']); $this->linter->setExceptionOnInvalidType($config['exception_on_invalid_type']); 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); }
/** * @test */ function it_should_handle_exceptions_on_invalid_type() { $this->linter->setObjectSupport(false); $this->linter->setExceptionOnInvalidType(true); $this->validateFixture('object-support.yml', 1); }