コード例 #1
0
 /**
  * @dataProvider upperBoundProvider
  */
 public function testSetUpperBound($bound, $testValue, $validity)
 {
     $definition = $this->getEmptyInstance();
     $definition->setArrayValues(array('upperbound' => $bound));
     $this->validate($definition, (string) $testValue, $validity);
     $options = new Options();
     $options->setRawStringInputs(false);
     $this->validate($definition, $testValue, $validity, $options);
 }
コード例 #2
0
 /**
  * Takes an array of unprocessed parameters,
  * and sets them on a new Validator object,
  * which is returned and ready to process the parameters.
  *
  * @since 1.8
  *
  * @param array $params
  * @param array $printRequests
  * @param boolean $unknownInvalid
  *
  * @return Processor
  */
 public static function getValidatorForParams(array $params, array $printRequests = array(), $unknownInvalid = true)
 {
     $paramDefinitions = self::getParameters();
     $paramDefinitions['format']->setPrintRequests($printRequests);
     $processorOptions = new Options();
     $processorOptions->setUnknownInvalid($unknownInvalid);
     $validator = Processor::newFromOptions($processorOptions);
     $validator->setParameters($params, $paramDefinitions, false);
     return $validator;
 }
コード例 #3
0
 /**
  * @dataProvider instanceProvider
  */
 public function testValidate(IParamDefinition $definition)
 {
     foreach (array(true, false) as $stringlyTyped) {
         $values = $this->valueProvider($stringlyTyped);
         $options = new Options();
         $options->setRawStringInputs($stringlyTyped);
         foreach ($values[$definition->getName()] as $data) {
             list($input, $valid, ) = $data;
             $param = new Param($definition);
             $param->setUserValue($definition->getName(), $input, $options);
             $definitions = array();
             $param->process($definitions, array(), $options);
             $this->assertEquals($valid, $param->getErrors() === array(), 'The validation process should ' . ($valid ? '' : 'not ') . 'pass');
         }
     }
     $this->assertTrue(true);
 }
コード例 #4
0
 /**
  * List parameters to test if list handling works correctly.
  *
  * @return array
  */
 private function getListParams()
 {
     $params = array('awesome' => ' yes, no, on, off ', 'float' => ' 9001 ; 42 ; 4.2;0');
     $definitions = array('awesome' => array('type' => 'boolean', 'islist' => true), 'text' => array('default' => array('bar'), 'islist' => true), 'float' => array('type' => 'float', 'islist' => true, 'delimiter' => ';'));
     $options = new Options();
     $options->setLowercaseValues(true);
     $options->setTrimValues(true);
     $expected = array('awesome' => array(true, false, true, false), 'text' => array('bar'), 'float' => array(9001.0, 42.0, 4.2, 0.0));
     return array($params, $definitions, $options, $expected);
 }
コード例 #5
0
 /**
  * @since 1.0
  *
  * @param Options $options
  *
  * @return ValueParser
  */
 public function getValueParser(Options $options)
 {
     $parser = $this->definition->getValueParser();
     if (get_class($parser) === 'ValueParsers\\NullParser') {
         $parserType = $options->isStringlyTyped() ? 'string-parser' : 'typed-parser';
         // TODO: inject factory
         $parserClass = ParamDefinitionFactory::singleton()->getComponentForType($this->definition->getType(), $parserType);
         if ($parserClass !== 'ValueParsers\\NullParser') {
             $parser = new $parserClass(new \ValueParsers\ParserOptions());
         }
     }
     return $parser;
 }