コード例 #1
0
ファイル: AnalyserTest.php プロジェクト: stefk/md
 public function testAnalyseWithEmptyRuleset()
 {
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
     $analyser = new Analyser($parser, new NodeTraverser(), new RuleSet(), new Reporter());
     $analyser->analyse('<?php echo "test";');
     $this->assertEquals([], $analyser->getReporter()->getViolations());
 }
コード例 #2
0
ファイル: RuleTestCase.php プロジェクト: stefk/md
 /**
  * @dataProvider sampleProvider
  */
 public function testSamples($file, array $expectedViolations)
 {
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
     $set = new Ruleset();
     $set->addRule($this->getRule());
     $analyser = new Analyser($parser, new NodeTraverser(), $set, new Reporter());
     $analyser->analyseFile($file);
     $violations = $analyser->getReporter()->getViolations();
     $count = count($violations);
     $expectedCount = count($expectedViolations);
     // @codeCoverageIgnoreStart
     if ($count === 0 && $expectedCount > 0) {
         $this->fail("{$expectedCount} violations were expected in {$file}, none found");
     }
     // @codeCoverageIgnoreEnd
     $stdViolations = array_map(function ($violation) {
         return $violation->toStdClass();
     }, $violations);
     $this->assertEquals($expectedViolations, $stdViolations, "\nExpected:\n" . json_encode($expectedViolations, JSON_PRETTY_PRINT) . "\nActual:\n" . json_encode($stdViolations, JSON_PRETTY_PRINT));
 }