示例#1
0
    $t->is($e[0]->getCode(), 's1_not_equal_s2', '->clean() throws an exception with all error messages');
}
$v = new Schema(array('s1' => $v1, 's2' => $v2));
$t->is($v->clean(array('s1' => 'foo')), array('s1' => 'foo', 's2' => null), '->clean() returns null values for fields not present in the input array');
$t->diag('extra fields');
$v = new Schema(array('s1' => $v1, 's2' => $v2));
$v->setOption('allow_extra_fields', true);
$ret = $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'));
$t->is($ret, array('s1' => 'foo', 's2' => 'bar'), '->clean() filters non existant fields if "allow_extra_fields" is true');
$v = new Schema(array('s1' => $v1, 's2' => $v2), array('allow_extra_fields' => true));
$ret = $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'));
$t->is($ret, array('s1' => 'foo', 's2' => 'bar'), '->clean() filters non existant fields if "allow_extra_fields" is true');
$v = new Schema(array('s1' => $v1, 's2' => $v2), array('allow_extra_fields' => true, 'filter_extra_fields' => false));
$ret = $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'));
$t->is($ret, array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'), '->clean() do not filter non existant fields if "filter_extra_fields" is false');
$v->setOption('filter_extra_fields', false);
$ret = $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'));
$t->is($ret, array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar'), '->clean() do not filter non existant fields if "filter_extra_fields" is false');
$t->diag('one validator fails');
$v['s2']->setOption('max_length', 2);
try {
    $v->clean(array('s1' => 'foo', 's2' => 'bar'));
    $t->fail('->clean() throws an ErrorSchema exception if one of the validators fails');
    $t->skip('', 2);
} catch (ErrorSchema $e) {
    $t->pass('->clean() throws an ErrorSchema exception if one of the validators fails');
    $t->is(count($e), 1, '->clean() throws an exception with all error messages');
    $t->is($e['s2']->getCode(), 'max_length', '->clean() throws an exception with all error messages');
}
$t->diag('several validators fail');
$v['s1']->setOption('max_length', 2);