public function testToString() { $format = new Format(); $expected = 'json'; $format->setFormat('json'); $this->assertSame($expected, $format->toString()); }
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); }
/** * 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; }
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); }