Пример #1
0
 public function testBooleanValidator()
 {
     $validator = new BooleanRule();
     $this->assertTrue($validator->validate($this->validator, false, Validator::SCENARIO_ALL));
     $this->assertTrue($validator->validate($this->validator, true, Validator::SCENARIO_ALL));
     $this->assertFalse($validator->validate($this->validator, 1, Validator::SCENARIO_ALL));
     $this->assertFalse($validator->validate($this->validator, null, Validator::SCENARIO_ALL));
 }
Пример #2
0
 public function testThatValidatorCallsRulesForScenario()
 {
     $std = new \stdClass();
     $std->prop = "foo";
     $std->other = "foo";
     $mockReader = $this->getMock(RuleReader::class, ['getObjectValidator']);
     $validator = new Validator($mockReader);
     $objectValidator = new ObjectValidator();
     $stringRule = new StringRule();
     $numberRule = new Number();
     $booleanRule = new BooleanRule();
     $stringRule->setScenario('string');
     $numberRule->setScenario('number');
     $objectValidator->addPropertyRule('prop', $stringRule);
     $objectValidator->addPropertyRule('prop', $numberRule);
     $mockReader->expects($this->any())->method('getObjectValidator')->with($this->equalTo($std))->will($this->returnValue($objectValidator));
     $this->assertFalse($validator->validate($std, "number"));
     $this->assertTrue($validator->validate($std, "string"));
     $booleanRule->setScenario(['string', 'number']);
     $objectValidator->addPropertyRule('other', $booleanRule);
     $this->assertFalse($validator->validate($std, "string"));
 }