public function setUp() { $ruleset = new RuleSet(); $ruleset->setRule('required', $this->createRequiredRule()); $ruleset->setRule('trim', $this->createTrimRule()); $ruleset->setRule('regex', $this->createRegexRule()); $this->ruleset = $ruleset; }
public function testOverrideRule() { $rule1 = $this->createMockRule(); $rule2 = $this->createMockRule(); $this->ruleSet->setRule('test', $rule1); $this->ruleSet->setRule('test', $rule2); $this->assertNotSame($this->ruleSet->getRule('test'), $rule1); $this->assertSame($this->ruleSet->getRule('test'), $rule2); }
public function testSetGetValidator() { $ruleSet = new RuleSet(); $ruleSet->setRule('required', $this->createRequiredRule()); $validator = new Validator($ruleSet, 'required', 'required field'); $this->field->setValidator($validator); $this->assertSame($validator, $this->field->getValidator()); }
/** * @expectedException \LiftKit\Form\Validator\Rule\Exception\Validation */ public function testExecuteValidates() { $input = new Request([]); $ruleSet = new RuleSet(); $ruleSet->setRule('required', new Rule(function ($value) { return (bool) $value; }, 'The field is required')); $element = new Field(); $element->setValidator(new Validator($ruleSet, 'required')); $this->fieldSet->attachElement($element); $this->fieldSet->execute($input); }