Merge pull request #85 from Typeform/master

Add instanceOf to rules in readme.md
This commit is contained in:
Vance Lucas 2014-07-29 13:00:00 -05:00
commit 6d36b12f76
4 changed files with 20 additions and 1 deletions

View File

@ -114,6 +114,7 @@ V::lang('ar');
* `dateAfter` - Field is a valid date and is after the given date
* `contains` - Field is a string and contains the given string
* `creditCard` - Field is a valid credit card number
* `instanceOf` - Field contains an instance of the given class
**NOTE**: If you are comparing floating-point numbers with min/max validators, you
should install the [BCMath](http://us3.php.net/manual/en/book.bc.php)

View File

@ -29,5 +29,6 @@ return array(
'lengthBetween' => "must be between %d and %d characters",
'creditCard' => "must be a valid credit card number",
"lengthMin" => "must contain greater than %d characters",
"lengthMax" => "must contain less than %d characters"
"lengthMax" => "must contain less than %d characters",
"instanceOf" => "must be an instance of '%s'"
);

View File

@ -736,6 +736,10 @@ class Validator
}
if ($param instanceof \DateTime) {
$param = $param->format('Y-m-d');
} else {
if(is_object($param)) {
$param = get_class($param);
}
}
// Use custom label instead of field name if set
if(is_string($params[0])) {

View File

@ -833,6 +833,19 @@ class ValidateTest extends BaseTestCase
$this->assertTrue($v->validate());
}
public function testInstanceOfErrorMessageShowsInstanceName()
{
$v = new Validator(array('attributeName' => new Validator(array())));
$v->rule('instanceOf', 'attributeName', new stdClass());
$v->validate();
$expected_error = array(
"attributeName" => array(
"AttributeName must be an instance of 'stdClass'"
)
);
$this->assertEquals($expected_error, $v->errors());
}
public function testInstanceOfInvalidWithString()
{
$v = new Validator(array('attributeName' => new stdClass()));