Exemplo n.º 1
0
 /**
  * @param string $field
  * @param string $msg
  * @return Hypercharge\Errors\ValidationError
  */
 static function create($field, $msg)
 {
     $e = new ValidationError();
     $e->add($field, $msg);
     $e->flush();
     return $e;
 }
Exemplo n.º 2
0
 function testValidationErrorAdd()
 {
     $errors = array();
     $e = new ValidationError();
     $this->assertEqual($e->message, '0 validation errors');
     $this->assertEqual($e->technical_message, '');
     $this->assertEqual($e->errors, $errors);
     $this->assertFalse($e->flush());
     $this->assertEqual($e->message, '0 validation errors');
     $this->assertEqual($e->technical_message, '');
     $errors[] = array('property' => 'a', 'message' => 'msg a');
     $e->add('a', 'msg a');
     $this->assertTrue($e->flush());
     $this->assertEqual($e->message, '1 validation error');
     $this->assertEqual($e->technical_message, '1 affected property: a');
     $this->assertEqual($e->errors, $errors);
     $errors[] = array('property' => 'b', 'message' => 'msg b');
     $e->add('b', 'msg b');
     $this->assertTrue($e->flush());
     $this->assertEqual($e->message, '2 validation errors');
     $this->assertEqual($e->technical_message, '2 affected properties: a, b');
     $this->assertEqual($e->errors, $errors);
 }