コード例 #1
0
ファイル: RulesBuilderTest.php プロジェクト: philiplb/valdi
 public function testCreatedRules()
 {
     $rules = RulesBuilder::create()->addRule('a', 'required')->addRule('b', 'min', 5)->getRules();
     $data = ['a' => 'abc', 'b' => 6];
     $validator = new Validator();
     $read = $validator->isValid($rules, $data);
     $expected = ['valid' => true, 'errors' => []];
     $this->assertSame($read, $expected);
 }
コード例 #2
0
ファイル: ValidatorTest.php プロジェクト: philiplb/valdi
 public function testAddValidator()
 {
     $validator = new Validator();
     $rules = ['a' => [['test']]];
     try {
         $validator->isValid($rules, ['a' => 1]);
         $this->fail();
     } catch (ValidatorException $e) {
         $read = $e->getMessage();
         $expected = '"test" not found as available validator.';
         $this->assertSame($read, $expected);
     } catch (\Exception $e) {
         $this->fail();
     }
     $validator->addValidator('test', new TestValidator());
     $read = $validator->isValid($rules, ['a' => 1]);
     $expected = ['valid' => false, 'errors' => ['a' => ['test']]];
     $this->assertSame($read, $expected);
     $read = $validator->isValid($rules, ['a' => 2]);
     $expected = ['valid' => true, 'errors' => []];
     $this->assertSame($read, $expected);
 }