public function testDate() { $form = new Validator(['birthday' => ['date']]); $this->assertTrue($form->validate(['birthday' => '2000-01-01'])); $this->assertFalse($form->validate(['birthday' => '01/01/2001'])); $form = new Validator(['birthday' => ['date' => null]]); $this->assertTrue($form->validate(['birthday' => '2000-01-01'])); $this->assertTrue($form->validate(['birthday' => '01/01/2001'])); }
<?php require 'vendor/autoload.php'; // form validator with json object use Form\Validator; $jsonObject = json_encode(['username' => 'nandeesh', 'email' => '*****@*****.**', 'password' => 'nandeesh', 'confirm-password' => 'nandeesh']); $rules = ['username' => 'required|Minlength:4', 'email' => 'required|email', 'password' => 'required', 'confirm-password' => 'required|same:password']; $validator = new Validator($rules, $jsonObject); echo 'Result : ' . $validator->isValid();
private function fails($rules, $object) { $validator = new Validator($rules, $object); $this->assertFalse($validator->isValid()); }