/** * Create response instance by query string * @param string $queryString query string * @return Code|Error response instance: error or code data * @throws RuntimeException when response has a suspect string */ private static function createResponseFromQuery($queryString) { $value = parse_url($queryString, PHP_URL_QUERY); if ($value !== false) { switch (true) { case strpos($value, 'error=') === 0: return Error::initializeByString($value); case strpos($value, 'code=') === 0: return Code::initializeByString($value); } } throw new RuntimeException(sprintf('suspect data returned: %s', $queryString)); }
public function testStringInitialization() { $Code = Code::initializeByString('code=someCode/1'); $this->assertEquals('someCode/1', $Code->getCode()); }