Ejemplo n.º 1
0
 public function __construct(Parser $parser, NodeTraverser $traverser, Ruleset $ruleset, Reporter $reporter)
 {
     $this->parser = $parser;
     $this->traverser = $traverser;
     $this->ruleset = $ruleset;
     $this->reporter = $reporter;
     $this->traverser->addVisitor(new NameResolver());
     foreach ($ruleset->getRules() as $rule) {
         $rule->setReporter($reporter);
         $this->traverser->addVisitor($rule);
     }
 }
Ejemplo n.º 2
0
 /**
  * @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));
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider invalidRuleTagsProvider
  * @expectedException \MD\Exception\InvalidRuleTagsException
  */
 public function testAddRuleWithInvalidTags($tags)
 {
     $set = new Ruleset();
     $set->addRule($this->mockRule('foo', 'desc', Levels::INFO, $tags));
 }