mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Show instance name in instanceOf error message
This commit is contained in:
parent
6f5dad8745
commit
9d90b08813
@ -736,6 +736,10 @@ class Validator
|
|||||||
}
|
}
|
||||||
if ($param instanceof \DateTime) {
|
if ($param instanceof \DateTime) {
|
||||||
$param = $param->format('Y-m-d');
|
$param = $param->format('Y-m-d');
|
||||||
|
} else {
|
||||||
|
if(is_object($param)) {
|
||||||
|
$param = get_class($param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Use custom label instead of field name if set
|
// Use custom label instead of field name if set
|
||||||
if(is_string($params[0])) {
|
if(is_string($params[0])) {
|
||||||
|
|||||||
@ -829,6 +829,19 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertTrue($v->validate());
|
$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()
|
public function testInstanceOfInvalidWithString()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('attributeName' => new stdClass()));
|
$v = new Validator(array('attributeName' => new stdClass()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user