Exemple #1
0
 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());
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 public function testGetRequirements()
 {
     $check = new Check();
     $this->assertTrue(is_array($check->getRequirements()));
 }