/**
  * @covers W3C\Validation\Result::setIsValid
  * @covers W3C\Validation\Result::isValid
  */
 public function testSetIsValid()
 {
     $this->result->setIsValid(false);
     $this->assertFalse($this->result->isValid());
     $this->result->setIsValid(true);
     $this->assertTrue($this->result->isValid());
 }
Exemplo n.º 2
0
 /**
  * @group response-validation
  * @test
  */
 public function the_result_correctly_reports_whether_or_not_it_is_valid()
 {
     $result = new Result();
     $this->assertTrue($result->isValid());
     $this->assertCount(0, $result->getErrors());
     $result->addError('Oh noooos!');
     $this->assertFalse($result->isValid());
     $this->assertCount(1, $result->getErrors());
 }
Exemplo n.º 3
0
 /**
  * Returns a result that represents the combination of the two given results.
  * In particular, this means:
  *
  * If $a->getErrors() is empty and $a->isValid() is true, $b is returned.
  * If $b->getErrors() is empty and $b->isValid() is true, $a is returned.
  *
  * Otherwise, a new Result is constructed that contains
  * all errors from $a and $b, and is considered valid
  * if both $a and $b were valid.
  *
  * @since 0.1
  *
  * @param Result $a
  * @param Result $b
  *
  * @return Result
  */
 public static function merge(Result $a, Result $b)
 {
     $aErrors = $a->getErrors();
     $bErrors = $b->getErrors();
     if ($a->isValid() && empty($aErrors)) {
         return $b;
     } elseif ($b->isValid() && empty($bErrors)) {
         return $a;
     } else {
         $errors = array_merge($aErrors, $bErrors);
         $valid = $a->isValid() && $b->isValid();
         return new Result($valid, $errors);
     }
 }
Exemplo n.º 4
0
 /**
  * @param  Result $result
  * @return $this
  */
 public function mergeWithResult(Result $result)
 {
     if ($this->_isValid && !$result->isValid()) {
         $this->_isValid = false;
     }
     $this->_errorMessages = array_merge($this->_errorMessages, $result->getErrorMessages());
     return $this;
 }