예제 #1
0
 /**
  * @test
  * @dataProvider dataToValidate
  */
 public function validate($data, $valid, $errors)
 {
     $validationRules = ['title' => ['name' => 'Title', 'required' => true, 'nullable' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]], 'name' => ['name' => 'Name', 'required' => true, 'type' => 'string', 'constraints' => ['length' => [1, null], 'callback' => [$this, 'callBackTest']]], 'age' => ['name' => 'Age', 'required' => false, 'type' => 'number', 'constraints' => ['integer' => true]], 'address' => ['name' => 'Address', 'required' => false, 'type' => 'object', 'properties' => ['line1' => ['required' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]], 'line2' => ['required' => false, 'type' => 'string'], 'postCode' => ['required' => true, 'type' => 'string', 'constraints' => ['length' => [3, 12]]]]], 'nickNames' => ['name' => 'Nick Names', 'required' => false, 'type' => 'array', 'items' => ['*' => ['type' => 'string', 'constraints' => ['length' => [1, null]]]]], 'languages' => ['name' => 'Languages', 'required' => false, 'type' => 'array', 'items' => ['*' => ['name' => 'Language', 'type' => 'string', 'constraints' => ['length' => [1, null]]]]], 'favouriteQuote' => ['name' => 'Favourite Quote', 'required' => false, 'nullable' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]]];
     $validator = new Validator();
     $this->assertEquals($valid, $validator->isValid($validationRules, $data));
     $this->assertEquals($errors, $validator->getErrors());
 }
예제 #2
0
 /**
  * @test
  * @expectedException Mooti\Validator\Exception\InvalidTypeValidatorException
  * @expectedExceptionMessage The type "foo" is invalid
  */
 public function getTypeValidatorThrowsInvalidTypeValidatorException()
 {
     $type = 'foo';
     $validator = new Validator();
     $validator->getTypeValidator($type);
 }