示例#1
0
 /**
  * @dataProvider evaluateProvider
  */
 public function testEvaluate(Constraint $constraint, $features, $values, $expected)
 {
     foreach ($features as $i => $f) {
         $f->setValue($values[$i]);
     }
     $result = $constraint->evaluate();
     $this->assertEquals($expected, $result);
 }
示例#2
0
 /**
  * Simplifies compound constraints. For e.g. when an AndX
  * is inside an other AndX, it gets simplified to a single
  * AndX.
  *
  * @param  Constraint       $constraint
  * @return Constraint|mixed
  */
 protected function canonicalize(Constraint $constraint)
 {
     if ($constraint instanceof CompoundConstraint) {
         $children = $constraint->getConstraints();
         if (1 === count($children) && $constraint instanceof AndX) {
             return $constraint->pop();
         }
         foreach ($children as &$child) {
             $child = $this->canonicalize($child);
         }
         $constraint->setConstraints($children);
     }
     return $constraint;
 }