Inheritance: implements GrumPHP\Linter\LinterInterface
示例#1
0
 function it_throws_exception_if_the_process_fails(JsonLinter $linter, ContextInterface $context)
 {
     $linter->isInstalled()->willReturn(true);
     $linter->setDetectKeyConflicts(false)->shouldBeCalled();
     $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new JsonLintError(LintError::TYPE_ERROR, 0, 'error', 'file.json', 1, 1))));
     $context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.json', '.', 'file.json'))));
     $this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
 }
示例#2
0
 function it_throws_exception_if_the_process_fails(JsonLinter $linter, ContextInterface $context)
 {
     $linter->isInstalled()->willReturn(true);
     $linter->setDetectKeyConflicts(false)->shouldBeCalled();
     $linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection([new JsonLintError(LintError::TYPE_ERROR, 0, 'error', 'file.json', 1, 1)]));
     $context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file.json', '.', 'file.json')]));
     $result = $this->run($context);
     $result->shouldBeAnInstanceOf(TaskResultInterface::class);
     $result->isPassed()->shouldBe(false);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.json');
     if (0 === count($files)) {
         return;
     }
     $config = $this->getConfiguration();
     $this->linter->setDetectKeyConflicts($config['detect_key_conflicts']);
     $lintErrors = $this->lint($files);
     if ($lintErrors->count()) {
         throw new RuntimeException($lintErrors->__toString());
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.json');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $this->linter->setDetectKeyConflicts($config['detect_key_conflicts']);
     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);
 }
示例#5
0
 /**
  * @test
  */
 function it_should_be_able_to_detect_duplicate_keys()
 {
     $this->linter->setDetectKeyConflicts(true);
     $this->validateFixture('duplicate-keys.json', 1);
 }