Fix #33 Validation for length - Message is incorrect for between cases

This commit is contained in:
Kilte 2014-01-07 00:08:09 +04:00
parent 97ae575141
commit db6d49baf6
2 changed files with 17 additions and 2 deletions

View File

@ -139,6 +139,21 @@ class Validator
return $this->validateRequired($field, $value) && in_array($value, $acceptable, true); return $this->validateRequired($field, $value) && in_array($value, $acceptable, true);
} }
/**
* Validate the length of a string
*
* @param string $filed
* @param mixed $value
* @param array $params
*
* @return boolean
*/
protected function validateLengthBetween($filed, $value, $params)
{
$length = $this->stringLength($value);
return $length >= $params[0] && $length <= $params[1];
}
/** /**
* Validate that a field is numeric * Validate that a field is numeric
* *

View File

@ -136,14 +136,14 @@ class ValidateTest extends BaseTestCase
public function testLengthBetweenValid() public function testLengthBetweenValid()
{ {
$v = new Validator(array('str' => 'happy')); $v = new Validator(array('str' => 'happy'));
$v->rule('length', 'str', 2, 8); $v->rule('lengthBetween', 'str', 2, 8);
$this->assertTrue($v->validate()); $this->assertTrue($v->validate());
} }
public function testLengthBetweenInvalid() public function testLengthBetweenInvalid()
{ {
$v = new Validator(array('str' => 'sad')); $v = new Validator(array('str' => 'sad'));
$v->rule('length', 'str', 4, 10); $v->rule('lengthBetween', 'str', 4, 10);
$this->assertFalse($v->validate()); $this->assertFalse($v->validate());
} }