示例#1
0
 public function testToString()
 {
     $format = new Format();
     $expected = 'json';
     $format->setFormat('json');
     $this->assertSame($expected, $format->toString());
 }
示例#2
0
 public function testCheckPassWithRequirements()
 {
     $supplied = 'jsonarray';
     $requirements = array('values' => array('jsonarray'));
     $format = new Format();
     $format->setFormat('jsonarray');
     $expected = $format;
     $actual = FormatType::check($supplied, $requirements);
     // Compare actual and existing params
     $this->assertInstanceOf(get_class($format), $actual);
     $this->assertEquals($expected, $actual);
 }
示例#3
0
 /**
  * Checks if the value is of a given type and
  * that the value passes requirements specified.
  *
  * @param   mixed   $value          Value to be checked
  * @param   array   $requirements   Additional constraints
  * @return  string  Cleared value
  * @throws  InvalidDataTypeException
  */
 public static function check($value, array $requirements = array())
 {
     // Default format options
     $allowedFormats = Format::$formatOptions;
     if (!is_string($value)) {
         $error = 'value must be one of: ' . implode(', ', $allowedFormats);
         throw new InvalidDataTypeException($error);
     }
     // Make sure format is alwas lowercase
     $value = strtolower((string) $value);
     $format = new Format();
     // Override list of supported formats if set
     if (!empty($requirements['values']) && is_array($requirements['values'])) {
         $allowedFormats = $requirements['values'];
     }
     if (!in_array($value, $allowedFormats)) {
         $error = 'value must be one of: ' . implode(', ', $allowedFormats);
         throw new InvalidDataValueException($error);
     }
     $format->setFormat($value);
     return $format;
 }
示例#4
0
 public function testCheckFormatPass()
 {
     $supplied = 'json';
     $format = new Format();
     $format->setFormat($supplied);
     $expected = $format;
     $requirements = array();
     $actual = PseudoTypes::checkFormat($supplied, $requirements);
     // Compare actual and existing params
     $this->assertInstanceOf(get_class($format), $actual);
     $this->assertEquals($expected, $actual);
 }