mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Merge pull request #85 from Typeform/master
Add instanceOf to rules in readme.md
This commit is contained in:
commit
6d36b12f76
@ -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)
|
||||
|
||||
@ -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'"
|
||||
);
|
||||
|
||||
@ -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])) {
|
||||
|
||||
@ -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()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user