Exemple #1
0
 /**
  * Callback rule must return instance of FieldValidationResult
  *
  * @expectedException Exception
  */
 public function testCallbackResult()
 {
     ArrayValidator::registerRule('uniqueName', function ($value, $data) {
         return true;
     });
     $validator = new ArrayValidator();
     $validator->field('name', ['uniqueName']);
     $validator->validate(array('name' => 'vtk'));
 }
Exemple #2
0
 public function testMultidimensionalObject()
 {
     $validator = new ArrayValidator();
     $validator->field('user.name')->required();
     $data = new stdClass();
     $data->user = new stdClass();
     $data->user->name = 'vtk';
     $result = $validator->validate($data);
     $this->assertTrue($result->isValid());
     $result = $validator->validate(new stdClass());
     $this->assertFalse($result->isValid());
 }
Exemple #3
0
 public function testAllValid()
 {
     $res = $this->validator->validate(array('name' => 'vtk', 'password1' => '1234', 'password2' => '1234', 'age' => 22));
     $this->assertTrue($res->isValid());
     $this->assertEquals(0, count($res->getAllMessages()));
 }