mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Fix bug where Validator::withData would also erase all rules
This commit is contained in:
parent
399004d172
commit
f8290a8c59
@ -1204,8 +1204,8 @@ class Validator
|
|||||||
public function withData($data, $fields = array())
|
public function withData($data, $fields = array())
|
||||||
{
|
{
|
||||||
$clone = clone $this;
|
$clone = clone $this;
|
||||||
$clone->reset();
|
|
||||||
$clone->_fields = !empty($fields) ? array_intersect_key($data, array_flip($fields)) : $data;
|
$clone->_fields = !empty($fields) ? array_intersect_key($data, array_flip($fields)) : $data;
|
||||||
|
$clone->_errors = array();
|
||||||
return $clone;
|
return $clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1164,10 +1164,16 @@ class ValidateTest extends BaseTestCase
|
|||||||
//validation failed, so must have errors
|
//validation failed, so must have errors
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
$this->assertNotEmpty($v->errors());
|
$this->assertNotEmpty($v->errors());
|
||||||
//create copy with different data
|
|
||||||
|
//create copy with valid data
|
||||||
$v2 = $v->withData(array('name' => 'Chester Tester'));
|
$v2 = $v->withData(array('name' => 'Chester Tester'));
|
||||||
$this->assertTrue($v2->validate());
|
$this->assertTrue($v2->validate());
|
||||||
$this->assertEmpty($v2->errors());
|
$this->assertEmpty($v2->errors());
|
||||||
|
|
||||||
|
//create copy with invalid data
|
||||||
|
$v3 = $v->withData(array('firstname' => 'Chester'));
|
||||||
|
$this->assertFalse($v3->validate());
|
||||||
|
$this->assertNotEmpty($v3->errors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user