コード例 #1
0
 /**
  * Test if NULL value fails validation when it is not allowed.
  */
 public function testNullFailsValidationWhenNotAllowed()
 {
     $validator = new Validator($this->connection, 'users', null, null, ['email' => null]);
     $is_valid_email = $validator->email('email', false);
     $this->assertFalse($is_valid_email);
     $this->assertTrue($validator->hasErrors());
     $email_errors = $validator->getFieldErrors('email');
     $this->assertInternalType('array', $email_errors);
     $this->assertCount(1, $email_errors);
 }
コード例 #2
0
 /**
  * Test if NULL value fails validation when it is not allowed.
  */
 public function testNullFailsValidationWhenNotAllowed()
 {
     $validator = new Validator($this->connection, 'users', null, null, ['continent' => null]);
     $is_valid_continent = $validator->inArray('continent', $this->continents);
     $this->assertFalse($is_valid_continent);
     $this->assertTrue($validator->hasErrors());
     $continent_errors = $validator->getFieldErrors('continent');
     $this->assertInternalType('array', $continent_errors);
     $this->assertCount(1, $continent_errors);
 }
コード例 #3
0
 /**
  * Test if NULL value fails validation when it is not allowed.
  */
 public function testNullFailsValidationWhenNotAllowed()
 {
     $validator = new Validator($this->connection, 'users', null, null, ['age' => null]);
     $is_valid_age = $validator->greaterThan('age', $this->min_age);
     $this->assertFalse($is_valid_age);
     $this->assertTrue($validator->hasErrors());
     $age_errors = $validator->getFieldErrors('age');
     $this->assertInternalType('array', $age_errors);
     $this->assertCount(1, $age_errors);
 }
コード例 #4
0
 /**
  * Test type check.
  */
 public function testTypeCheck()
 {
     $validator = new Validator($this->connection, 'writers', null, null, ['name' => '0']);
     $is_present = $validator->present('name');
     $this->assertTrue($is_present);
     $this->assertFalse($validator->hasErrors());
     $name_errors = $validator->getFieldErrors('name');
     $this->assertInternalType('array', $name_errors);
     $this->assertCount(0, $name_errors);
 }
コード例 #5
0
 /**
  * Test if NULL value fails validation when it is not allowed.
  */
 public function testNullFailsValidationWhenNotAllowed()
 {
     $validator = new Validator($this->connection, 'users', null, null, ['homepage_url' => null]);
     $is_valid_url = $validator->url('homepage_url', false);
     $this->assertFalse($is_valid_url);
     $this->assertTrue($validator->hasErrors());
     $url_errors = $validator->getFieldErrors('homepage_url');
     $this->assertInternalType('array', $url_errors);
     $this->assertCount(1, $url_errors);
     $this->assertContains("Value of 'homepage_url' is required", $url_errors);
 }
コード例 #6
0
 /**
  * Test if validator properly produces and populates ValidationException.
  */
 public function testValidatorException()
 {
     $validator = new Validator($this->connection, 'writers', null, null, ['name' => 'Leo Tolstoy']);
     $is_unique = $validator->unique('name');
     $this->assertFalse($is_unique);
     $this->assertTrue($validator->hasErrors());
     $exception = $validator->createException();
     $this->assertInstanceOf(ValidationException::class, $exception);
     $this->assertTrue($exception->hasErrors());
     $this->assertTrue($exception->hasError('name'));
     $this->assertFalse($exception->hasError('unknown_column_here'));
 }
コード例 #7
0
 public function testValidatorReturnsAllErrors()
 {
     $validator = new Validator($this->connection, 'writers', null, null, ['name' => 'Leo Tolstoy', 'birthday' => null]);
     $validator->unique('name');
     $validator->present('birthday');
     $this->assertTrue($validator->hasErrors());
     $errors = $validator->getErrors();
     $this->assertInternalType('array', $errors);
     $this->assertCount(2, $errors);
     $this->assertArrayHasKey('name', $errors);
     $this->assertInternalType('array', $errors['name']);
     $this->assertCount(1, $errors['name']);
     $this->assertEquals("Value of 'name' needs to be unique", $errors['name'][0]);
     $this->assertArrayHasKey('birthday', $errors);
     $this->assertInternalType('array', $errors['birthday']);
     $this->assertCount(1, $errors['birthday']);
     $this->assertEquals("Value of 'birthday' is required", $errors['birthday'][0]);
 }
コード例 #8
0
 /**
  * Test unique where filter properly reports an error when conditions are met.
  */
 public function testErrorWhenUniqueWhereIsMatched()
 {
     $validator = new Validator($this->connection, 'writers', null, null, ['name' => 'Leo Tolstoy']);
     $is_unique = $validator->uniqueWhere('name', ['birthday < ?', new DateValue('1900-01-01')]);
     $this->assertFalse($is_unique);
     $this->assertTrue($validator->hasErrors());
     $name_errors = $validator->getFieldErrors('name');
     $this->assertInternalType('array', $name_errors);
     $this->assertCount(1, $name_errors);
 }