public function withData($data, $fields = array())
{
$clone = clone $this;
$clone->reset();
$clone->_fields = !empty($fields) ? array_intersect_key($data, array_flip($fields)) : $data;
return $clone;
}
public function testWithData() { $v = new Validator(array()); $v->rule('required', 'name'); //validation failed, so must have errors $this->assertFalse($v->validate()); $this->assertNotEmpty($v->errors()); //create copy with different data $v2 = $v->withData(array('name' => 'Chester Tester')); $this->assertTrue($v2->validate()); $this->assertEmpty($v2->errors()); }