Test fixes

This commit is contained in:
Dennis Eichhorn 2017-08-22 12:46:56 +02:00
parent adc335d0e6
commit 9dedf9303e
11 changed files with 79 additions and 21 deletions

View File

@ -645,7 +645,7 @@ class FinanceFormulas
*
* @since 1.0.0
*/
public static function getCurrentRaio(float $assets, float $liabilities) : float
public static function getCurrentRatio(float $assets, float $liabilities) : float
{
return $assets / $liabilities;
}

View File

@ -117,7 +117,7 @@ class Header extends HeaderAbstract
*/
public static function getStatusCode() : int
{
return http_response_code();
return \http_response_code();
}
/**
@ -129,7 +129,7 @@ class Header extends HeaderAbstract
*/
public function getHeaders() : array
{
return getallheaders();
return self::getAllHeaders();
}
/**
@ -141,7 +141,30 @@ class Header extends HeaderAbstract
*/
public function getHeader(string $name) : string
{
return getallheaders()[$name];
return self::getAllHeaders()[$name] ?? '';
}
/**
* Get all headers for apache and nginx
*
* @return array
*
* @since 1.0.0
*/
private static function getAllHeaders() : array
{
if (function_exists('getallheaders')) {
return getallheaders();
}
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
/**
@ -257,7 +280,7 @@ class Header extends HeaderAbstract
{
$this->set('HTTP', 'HTTP/1.0 403 Forbidden');
$this->set('Status', 'Status: HTTP/1.0 403 Forbidden');
http_response_code(403);
\http_response_code(403);
}
/**
@ -271,7 +294,7 @@ class Header extends HeaderAbstract
{
$this->set('HTTP', 'HTTP/1.0 404 Not Found');
$this->set('Status', 'Status: HTTP/1.0 404 Not Found');
http_response_code(404);
\http_response_code(404);
}
/**
@ -285,7 +308,7 @@ class Header extends HeaderAbstract
{
$this->set('HTTP', 'HTTP/1.0 406 Not acceptable');
$this->set('Status', 'Status: 406 Not acceptable');
http_response_code(406);
\http_response_code(406);
}
/**
@ -312,7 +335,7 @@ class Header extends HeaderAbstract
$this->set('HTTP', 'HTTP/1.0 500 Internal Server Error');
$this->set('Status', 'Status: 500 Internal Server Error');
$this->set('Retry-After', 'Retry-After: 300');
http_response_code(500);
\http_response_code(500);
}
/**
@ -327,6 +350,6 @@ class Header extends HeaderAbstract
$this->set('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
$this->set('Status', 'Status: 503 Service Temporarily Unavailable');
$this->set('Retry-After', 'Retry-After: 300');
http_response_code(503);
\http_response_code(503);
}
}

View File

@ -96,6 +96,16 @@ class Request extends RequestAbstract
return new self($l11n);
}
/**
* {@inheritdoc}
*/
public function setUri(UriInterface $uri) /* : void */
{
$this->uri = $uri;
$this->path = explode('/', $this->uri->getPath());
$this->data += $uri->getQueryArray();
}
/**
* Init request.
*

View File

@ -62,15 +62,13 @@ class Response extends ResponseAbstract implements RenderableInterface
/**
* Remove response by ID.
*
* @param int $id Response ID
* @param mixed $id Response ID
*
* @return bool
*
* @throws \Exception
*
* @since 1.0.0
*/
public function remove(int $id) : bool
public function remove($id) : bool
{
if (isset($this->response[$id])) {
unset($this->response[$id]);

View File

@ -214,7 +214,7 @@ abstract class RequestAbstract implements MessageInterface
public function setRequestSource(int $source) /* : void */
{
if (!RequestSource::isValidValue($source)) {
throw new InvalidEnumValue($source);
throw new InvalidEnumValue((string) $source);
}
$this->source = $source;

View File

@ -60,7 +60,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
* @var int
* @since 1.0.0
*/
protected $account = null;
protected $account = 0;
/**
* Header.
@ -122,7 +122,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
* {@inheritdoc}
* todo: shouldn't this only be available in the header?!
*/
public function getStatusCode() : string
public function getStatusCode() : int
{
return $this->status;
}

View File

@ -165,6 +165,8 @@ class Http implements UriInterface
parse_str($this->queryString, $this->query);
}
$this->query = array_change_key_case($this->query, CASE_LOWER);
$this->fragment = $url['fragment'] ?? '';
$this->base = $this->scheme . '://' . $this->host . $this->rootPath;
}
@ -282,7 +284,21 @@ class Http implements UriInterface
*/
public function getQuery(string $key = null) /* : ?string */
{
return isset($key) ? $this->query[$key] ?? null : $this->queryString;
if(isset($key)) {
$key = strtolower($key);
return $this->query[$key] ?? '';
}
return $this->queryString;
}
/**
* {@inheritdoc}
*/
public function getQueryArray() : array
{
return $this->query;
}
/**

View File

@ -117,6 +117,11 @@ class UriFactory
self::setQuery('/', $uri->getPath());
self::setQuery(':user', $uri->getUser());
self::setQuery(':pass', $uri->getPass());
$data = $uri->getQueryArray();
foreach($data as $key => $value) {
self::setQuery('?' . $key, $value);
}
}
/**
@ -224,7 +229,7 @@ class UriFactory
*/
public static function build(string $uri, array $toMatch = []) /* : ?string */
{
$parsed = preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) {
$parsed = preg_replace_callback('(\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) {
$match = substr($match[0], 1, strlen($match[0]) - 2);
return $toMatch[$match] ?? self::$uri[$match] ?? $match;

View File

@ -320,7 +320,7 @@ class ArrayUtils
*/
public static function arraySum(array $array, int $start = 0, int $count = 0)
{
$count = $count === 0 ? count($array) : $count;
$count = $count === 0 ? count($array) : $start + $count;
$sum = 0;
$array = array_values($array);

View File

@ -108,11 +108,11 @@ class JsonBuilder implements \Serializable, \JsonSerializable
*/
public function unserialize($serialized)
{
$this->json = json_decode($serialized);
$this->json = json_decode($serialized, true);
}
public function jsonSerialize()
{
return $this->json();
return $this->getJson();
}
}

View File

@ -58,4 +58,10 @@ abstract class ValidatorAbstract implements ValidatorInterface
{
return self::$error;
}
public static function resetError() /* : void */
{
self::$error = 0;
self::$msg = '';
}
}