function it_checks_an_invalid_node_with_only_rule(RuleInterface $rule, NodeInterface $node, ViolationInterface $violation)
 {
     $rule->getSubject()->willReturn('foo\\bar');
     $rule->getRequirements()->willReturn(array('blu', 'bla', 'bli'));
     $rule->getType()->willReturn(RuleInterface::TYPE_ONLY);
     $node->getSubject()->willReturn('foo\\bar\\baz');
     $node->getTokens()->willReturn(array('blu', 'bla', 'blo', 'bly'));
     $violation->getNode()->willReturn($node);
     $violation->getRule()->willReturn($rule);
     $violation->getType()->willReturn(ViolationInterface::TYPE_ERROR);
     $violation->getTokenViolations()->willReturn(array('blo', 'bly'));
     $this->check($rule, $node)->shouldBeLikeExpectedViolation($violation);
 }
Пример #2
0
 /**
  * Checks if a node respects a "only" rule.
  * A node respects such a rule if the node contains only tokens defined in the rule.
  *
  * @param RuleInterface $rule
  * @param NodeInterface $node
  *
  * @return Violation|null
  */
 private function checkOnlyRule(RuleInterface $rule, NodeInterface $node)
 {
     $errors = array();
     foreach ($node->getTokens() as $token) {
         if (!$this->checkTokenForOnlyRule($rule, $token) && !in_array($token, $errors)) {
             $errors[] = $token;
         }
     }
     if (count($errors)) {
         return new Violation($node, $rule, $errors, ViolationInterface::TYPE_ERROR);
     }
     return;
 }