コード例 #1
0
ファイル: ValidatorTest.php プロジェクト: rybakdigital/ucc
 public function testClearChecks()
 {
     $validator = new Validator();
     $firstCheck = array('name' => array('type' => 'string', 'min' => 1));
     $secondCheck = array('age' => array('type' => 'int', 'default' => 18, 'opt' => false));
     $nameCheck = new Check();
     $nameCheck->fromArray($firstCheck);
     $ageCheck = new Check();
     $ageCheck->fromArray($secondCheck);
     $checks = array($nameCheck, $ageCheck);
     $expected = array('name' => $nameCheck, 'age' => $ageCheck);
     $this->assertInstanceOf(get_class($validator), $validator->setChecks($checks));
     $this->assertEquals($expected, $validator->getChecks());
     $this->assertInstanceOf(get_class($validator), $validator->clearChecks());
     $this->assertEmpty($validator->getChecks());
 }
コード例 #2
0
ファイル: Validator.php プロジェクト: rybakdigital/ucc
 /**
  * Validates input field
  *
  * @param mixed $input      Data to validate
  * @param Check $check      Check to perform on input data
  * @return Validator
  */
 private function checkInput($input, $check)
 {
     $ret = false;
     // Check is specific type required
     if ($check->hasRequirement('type')) {
         $type = $check->getRequirement('type');
         if (in_array($type, array_keys(BasicTypes::$knownTypes))) {
             $method = BasicTypes::$knownTypes[$type];
             $callable = array('Ucc\\Data\\Types\\Basic\\BasicTypes', $method);
         } elseif (in_array($type, array_keys(PseudoTypes::$knownTypes))) {
             $method = PseudoTypes::$knownTypes[$type];
             $callable = array('Ucc\\Data\\Types\\Pseudo\\PseudoTypes', $method);
             // Check if custom class is called
         } elseif ($type == 'custom' && $check->hasRequirement('class') && $check->hasRequirement('method')) {
             $method = $check->getRequirement('method');
             $callable = array($check->getRequirement('method'), $method);
         }
     }
     $res = $this->checkValue($check->getKey(), $input, $check->getRequirements(), $callable);
     return $this;
 }
コード例 #3
0
ファイル: CheckTest.php プロジェクト: rybakdigital/ucc
 public function testGetRequirements()
 {
     $check = new Check();
     $this->assertTrue(is_array($check->getRequirements()));
 }