Convert simple string literals to single quotes
This commit is contained in:
parent
fb18d2ee1e
commit
002bdb7541
|
|
@ -10,4 +10,5 @@ return PhpCsFixer\Config::create()
|
||||||
->setRules([
|
->setRules([
|
||||||
'@PSR2' => true,
|
'@PSR2' => true,
|
||||||
'array_syntax' => ['syntax' => 'short'],
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
|
'single_quote' => true
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,7 +96,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function seek($offset, $whence = SEEK_SET)
|
public function seek($offset, $whence = SEEK_SET)
|
||||||
{
|
{
|
||||||
throw new \RuntimeException("Unable to seek to position.");
|
throw new \RuntimeException('Unable to seek to position.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,7 +109,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
throw new \RuntimeException("Unable to rewind stream.");
|
throw new \RuntimeException('Unable to rewind stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,7 +131,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function write($string)
|
public function write($string)
|
||||||
{
|
{
|
||||||
throw new \RuntimeException("Unable to write to stream.");
|
throw new \RuntimeException('Unable to write to stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -156,7 +156,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function read($length)
|
public function read($length)
|
||||||
{
|
{
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -168,7 +168,7 @@ class NullStream implements StreamInterface
|
||||||
*/
|
*/
|
||||||
public function getContents()
|
public function getContents()
|
||||||
{
|
{
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ class Request extends Message implements RequestInterface
|
||||||
$target = $this->uri->getPath();
|
$target = $this->uri->getPath();
|
||||||
$query = $this->uri->getQuery();
|
$query = $this->uri->getQuery();
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$target .= "?" . $query;
|
$target .= '?' . $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return "/" if the origin form is empty.
|
// Return "/" if the origin form is empty.
|
||||||
return $target ?: "/";
|
return $target ?: '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -187,18 +187,18 @@ class Request extends Message implements RequestInterface
|
||||||
$request = clone $this;
|
$request = clone $this;
|
||||||
|
|
||||||
$newHost = $uri->getHost();
|
$newHost = $uri->getHost();
|
||||||
$oldHost = isset($request->headers["Host"]) ? $request->headers["Host"] : "";
|
$oldHost = isset($request->headers['Host']) ? $request->headers['Host'] : '';
|
||||||
|
|
||||||
if ($preserveHost === false) {
|
if ($preserveHost === false) {
|
||||||
// Update Host
|
// Update Host
|
||||||
if ($newHost && $newHost !== $oldHost) {
|
if ($newHost && $newHost !== $oldHost) {
|
||||||
unset($request->headers["Host"]);
|
unset($request->headers['Host']);
|
||||||
$request->headers["Host"] = $newHost;
|
$request->headers['Host'] = $newHost;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Preserve Host
|
// Preserve Host
|
||||||
if (!$oldHost && $newHost) {
|
if (!$oldHost && $newHost) {
|
||||||
$request->headers["Host"] = $newHost;
|
$request->headers['Host'] = $newHost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,11 +216,11 @@ class Request extends Message implements RequestInterface
|
||||||
private function getValidatedMethod($method)
|
private function getValidatedMethod($method)
|
||||||
{
|
{
|
||||||
if (!is_string($method)) {
|
if (!is_string($method)) {
|
||||||
throw new \InvalidArgumentException("Method must be a string.");
|
throw new \InvalidArgumentException('Method must be a string.');
|
||||||
}
|
}
|
||||||
$method = trim($method);
|
$method = trim($method);
|
||||||
if (strpos($method, " ") !== false) {
|
if (strpos($method, ' ') !== false) {
|
||||||
throw new \InvalidArgumentException("Method cannot contain spaces.");
|
throw new \InvalidArgumentException('Method cannot contain spaces.');
|
||||||
}
|
}
|
||||||
return $method;
|
return $method;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class Response extends Message implements ResponseInterface
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException For invalid status code arguments.
|
* @throws \InvalidArgumentException For invalid status code arguments.
|
||||||
*/
|
*/
|
||||||
public function withStatus($code, $reasonPhrase = "")
|
public function withStatus($code, $reasonPhrase = '')
|
||||||
{
|
{
|
||||||
$response = clone $this;
|
$response = clone $this;
|
||||||
$response->statusCode = $code;
|
$response->statusCode = $code;
|
||||||
|
|
@ -111,64 +111,64 @@ class Response extends Message implements ResponseInterface
|
||||||
private function getDefaultReasonPhraseForStatusCode($statusCode)
|
private function getDefaultReasonPhraseForStatusCode($statusCode)
|
||||||
{
|
{
|
||||||
$reasonPhraseLookup = [
|
$reasonPhraseLookup = [
|
||||||
100 => "Continue",
|
100 => 'Continue',
|
||||||
101 => "Switching Protocols",
|
101 => 'Switching Protocols',
|
||||||
102 => "Processing",
|
102 => 'Processing',
|
||||||
200 => "OK",
|
200 => 'OK',
|
||||||
201 => "Created",
|
201 => 'Created',
|
||||||
202 => "Accepted",
|
202 => 'Accepted',
|
||||||
203 => "Non-Authoritative Information",
|
203 => 'Non-Authoritative Information',
|
||||||
204 => "No Content",
|
204 => 'No Content',
|
||||||
205 => "Reset Content",
|
205 => 'Reset Content',
|
||||||
206 => "Partial Content",
|
206 => 'Partial Content',
|
||||||
207 => "Multi-Status",
|
207 => 'Multi-Status',
|
||||||
208 => "Already Reported",
|
208 => 'Already Reported',
|
||||||
226 => "IM Used",
|
226 => 'IM Used',
|
||||||
300 => "Multiple Choices",
|
300 => 'Multiple Choices',
|
||||||
301 => "Moved Permanently",
|
301 => 'Moved Permanently',
|
||||||
302 => "Found",
|
302 => 'Found',
|
||||||
303 => "See Other",
|
303 => 'See Other',
|
||||||
304 => "Not Modified",
|
304 => 'Not Modified',
|
||||||
305 => "Use Proxy",
|
305 => 'Use Proxy',
|
||||||
307 => "Temporary Redirect",
|
307 => 'Temporary Redirect',
|
||||||
308 => "Permanent Redirect",
|
308 => 'Permanent Redirect',
|
||||||
400 => "Bad Request",
|
400 => 'Bad Request',
|
||||||
401 => "Unauthorized",
|
401 => 'Unauthorized',
|
||||||
402 => "Payment Required",
|
402 => 'Payment Required',
|
||||||
403 => "Forbidden",
|
403 => 'Forbidden',
|
||||||
404 => "Not Found",
|
404 => 'Not Found',
|
||||||
405 => "Method Not Allowed",
|
405 => 'Method Not Allowed',
|
||||||
406 => "Not Acceptable",
|
406 => 'Not Acceptable',
|
||||||
407 => "Proxy Authentication Required",
|
407 => 'Proxy Authentication Required',
|
||||||
408 => "Request Timeout",
|
408 => 'Request Timeout',
|
||||||
409 => "Conflict",
|
409 => 'Conflict',
|
||||||
410 => "Gone",
|
410 => 'Gone',
|
||||||
411 => "Length Required",
|
411 => 'Length Required',
|
||||||
412 => "Precondition Failed",
|
412 => 'Precondition Failed',
|
||||||
413 => "Payload Too Large",
|
413 => 'Payload Too Large',
|
||||||
414 => "URI Too Long",
|
414 => 'URI Too Long',
|
||||||
415 => "Unsupported Media Type",
|
415 => 'Unsupported Media Type',
|
||||||
416 => "Range Not Satisfiable",
|
416 => 'Range Not Satisfiable',
|
||||||
417 => "Expectation Failed",
|
417 => 'Expectation Failed',
|
||||||
421 => "Misdirected Request",
|
421 => 'Misdirected Request',
|
||||||
422 => "Unprocessable Entity",
|
422 => 'Unprocessable Entity',
|
||||||
423 => "Locked",
|
423 => 'Locked',
|
||||||
424 => "Failed Dependency",
|
424 => 'Failed Dependency',
|
||||||
426 => "Upgrade Required",
|
426 => 'Upgrade Required',
|
||||||
428 => "Precondition Required",
|
428 => 'Precondition Required',
|
||||||
429 => "Too Many Requests",
|
429 => 'Too Many Requests',
|
||||||
431 => "Request Header Fields Too Large",
|
431 => 'Request Header Fields Too Large',
|
||||||
500 => "Internal Server Error",
|
500 => 'Internal Server Error',
|
||||||
501 => "Not Implemented",
|
501 => 'Not Implemented',
|
||||||
502 => "Bad Gateway",
|
502 => 'Bad Gateway',
|
||||||
503 => "Service Unavailable",
|
503 => 'Service Unavailable',
|
||||||
504 => "Gateway Timeout",
|
504 => 'Gateway Timeout',
|
||||||
505 => "HTTP Version Not Supported",
|
505 => 'HTTP Version Not Supported',
|
||||||
506 => "Variant Also Negotiates",
|
506 => 'Variant Also Negotiates',
|
||||||
507 => "Insufficient Storage",
|
507 => 'Insufficient Storage',
|
||||||
508 => "Loop Detected",
|
508 => 'Loop Detected',
|
||||||
510 => "Not Extended",
|
510 => 'Not Extended',
|
||||||
511 => "Network Authentication Required"
|
511 => 'Network Authentication Required'
|
||||||
];
|
];
|
||||||
return $reasonPhraseLookup[$statusCode] ?? '';
|
return $reasonPhraseLookup[$statusCode] ?? '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
{
|
{
|
||||||
if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
|
if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
"withUploadedFiles expects an array tree with UploadedFileInterface leaves."
|
'withUploadedFiles expects an array tree with UploadedFileInterface leaves.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,7 +249,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
public function withParsedBody($data)
|
public function withParsedBody($data)
|
||||||
{
|
{
|
||||||
if (!(is_null($data) || is_array($data) || is_object($data))) {
|
if (!(is_null($data) || is_array($data) || is_object($data))) {
|
||||||
throw new \InvalidArgumentException("Parsed body must be null, array, or object.");
|
throw new \InvalidArgumentException('Parsed body must be null, array, or object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = clone $this;
|
$request = clone $this;
|
||||||
|
|
@ -350,15 +350,15 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
$this->readUploadedFiles($_FILES);
|
$this->readUploadedFiles($_FILES);
|
||||||
$this->queryParams = [];
|
$this->queryParams = [];
|
||||||
$this->uri = $this->readUri();
|
$this->uri = $this->readUri();
|
||||||
if (isset($_SERVER["QUERY_STRING"])) {
|
if (isset($_SERVER['QUERY_STRING'])) {
|
||||||
parse_str($_SERVER["QUERY_STRING"], $this->queryParams);
|
parse_str($_SERVER['QUERY_STRING'], $this->queryParams);
|
||||||
}
|
}
|
||||||
if (isset($_SERVER["SERVER_PROTOCOL"]) && $_SERVER["SERVER_PROTOCOL"] === "HTTP/1.0") {
|
if (isset($_SERVER['SERVER_PROTOCOL']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.0') {
|
||||||
// The default is 1.1, so only update if 1.0
|
// The default is 1.1, so only update if 1.0
|
||||||
$this->protocolVersion = "1.0";
|
$this->protocolVersion = '1.0';
|
||||||
}
|
}
|
||||||
if (isset($_SERVER["REQUEST_METHOD"])) {
|
if (isset($_SERVER['REQUEST_METHOD'])) {
|
||||||
$this->method = $_SERVER["REQUEST_METHOD"];
|
$this->method = $_SERVER['REQUEST_METHOD'];
|
||||||
}
|
}
|
||||||
$headers = $this->getServerRequestHeaders();
|
$headers = $this->getServerRequestHeaders();
|
||||||
foreach ($headers as $key => $value) {
|
foreach ($headers as $key => $value) {
|
||||||
|
|
@ -366,9 +366,9 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
}
|
}
|
||||||
$this->body = $this->getStreamForBody();
|
$this->body = $this->getStreamForBody();
|
||||||
|
|
||||||
$contentType = $this->getHeaderLine("Content-type");
|
$contentType = $this->getHeaderLine('Content-type');
|
||||||
if (strpos($contentType, "application/x-www-form-urlencoded") !== false
|
if (strpos($contentType, 'application/x-www-form-urlencoded') !== false
|
||||||
|| strpos($contentType, "multipart/form-data") !== false) {
|
|| strpos($contentType, 'multipart/form-data') !== false) {
|
||||||
$this->parsedBody = $_POST;
|
$this->parsedBody = $_POST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -388,37 +388,37 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
array $value
|
array $value
|
||||||
): void {
|
): void {
|
||||||
// Check for each of the expected keys.
|
// Check for each of the expected keys.
|
||||||
if (isset($value["name"], $value["type"], $value["tmp_name"], $value["error"], $value["size"])) {
|
if (isset($value['name'], $value['type'], $value['tmp_name'], $value['error'], $value['size'])) {
|
||||||
// This is a file. It may be a single file, or a list of files.
|
// This is a file. It may be a single file, or a list of files.
|
||||||
|
|
||||||
// Check if these items are arrays.
|
// Check if these items are arrays.
|
||||||
if (is_array($value["name"])
|
if (is_array($value['name'])
|
||||||
&& is_array($value["type"])
|
&& is_array($value['type'])
|
||||||
&& is_array($value["tmp_name"])
|
&& is_array($value['tmp_name'])
|
||||||
&& is_array($value["error"])
|
&& is_array($value['error'])
|
||||||
&& is_array($value["size"])
|
&& is_array($value['size'])
|
||||||
) {
|
) {
|
||||||
// Each item is an array. This is a list of uploaded files.
|
// Each item is an array. This is a list of uploaded files.
|
||||||
$files = [];
|
$files = [];
|
||||||
$keys = array_keys($value["name"]);
|
$keys = array_keys($value['name']);
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$files[$key] = new UploadedFile(
|
$files[$key] = new UploadedFile(
|
||||||
$value["name"][$key],
|
$value['name'][$key],
|
||||||
$value["type"][$key],
|
$value['type'][$key],
|
||||||
$value["size"][$key],
|
$value['size'][$key],
|
||||||
$value["tmp_name"][$key],
|
$value['tmp_name'][$key],
|
||||||
$value["error"][$key]
|
$value['error'][$key]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$branch[$name] = $files;
|
$branch[$name] = $files;
|
||||||
} else {
|
} else {
|
||||||
// All expected keys are present and are not arrays. This is an uploaded file.
|
// All expected keys are present and are not arrays. This is an uploaded file.
|
||||||
$uploadedFile = new UploadedFile(
|
$uploadedFile = new UploadedFile(
|
||||||
$value["name"],
|
$value['name'],
|
||||||
$value["type"],
|
$value['type'],
|
||||||
$value["size"],
|
$value['size'],
|
||||||
$value["tmp_name"],
|
$value['tmp_name'],
|
||||||
$value["error"]
|
$value['error']
|
||||||
);
|
);
|
||||||
$branch[$name] = $uploadedFile;
|
$branch[$name] = $uploadedFile;
|
||||||
}
|
}
|
||||||
|
|
@ -434,21 +434,21 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
|
|
||||||
protected function readUri(): UriInterface
|
protected function readUri(): UriInterface
|
||||||
{
|
{
|
||||||
$uri = "";
|
$uri = '';
|
||||||
|
|
||||||
$scheme = "http";
|
$scheme = 'http';
|
||||||
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && $_SERVER["HTTPS"] !== "off") {
|
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off') {
|
||||||
$scheme = "https";
|
$scheme = 'https';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SERVER["HTTP_HOST"])) {
|
if (isset($_SERVER['HTTP_HOST'])) {
|
||||||
$authority = $_SERVER["HTTP_HOST"];
|
$authority = $_SERVER['HTTP_HOST'];
|
||||||
$uri .= "$scheme://$authority";
|
$uri .= "$scheme://$authority";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path and query string
|
// Path and query string
|
||||||
if (isset($_SERVER["REQUEST_URI"])) {
|
if (isset($_SERVER['REQUEST_URI'])) {
|
||||||
$uri .= $_SERVER["REQUEST_URI"];
|
$uri .= $_SERVER['REQUEST_URI'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Uri($uri);
|
return new Uri($uri);
|
||||||
|
|
@ -478,8 +478,8 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
*/
|
*/
|
||||||
protected function getStreamForBody()
|
protected function getStreamForBody()
|
||||||
{
|
{
|
||||||
$input = fopen("php://input", "rb");
|
$input = fopen('php://input', 'rb');
|
||||||
$temp = fopen("php://temp", "wb+");
|
$temp = fopen('php://temp', 'wb+');
|
||||||
stream_copy_to_stream($input, $temp);
|
stream_copy_to_stream($input, $temp);
|
||||||
rewind($temp);
|
rewind($temp);
|
||||||
return new Stream($temp);
|
return new Stream($temp);
|
||||||
|
|
@ -495,7 +495,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
||||||
$headers = [];
|
$headers = [];
|
||||||
foreach ($_SERVER as $name => $value) {
|
foreach ($_SERVER as $name => $value) {
|
||||||
if (substr($name, 0, 5) === "HTTP_") {
|
if (substr($name, 0, 5) === 'HTTP_') {
|
||||||
$name = $this->normalizeHeaderName(substr($name, 5));
|
$name = $this->normalizeHeaderName(substr($name, 5));
|
||||||
$headers[$name] = trim($value);
|
$headers[$name] = trim($value);
|
||||||
} elseif ($this->isContentHeader($name) && !empty(trim($value))) {
|
} elseif ($this->isContentHeader($name) && !empty(trim($value))) {
|
||||||
|
|
@ -517,8 +517,8 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
*/
|
*/
|
||||||
private function normalizeHeaderName($name)
|
private function normalizeHeaderName($name)
|
||||||
{
|
{
|
||||||
$name = ucwords(strtolower(str_replace("_", " ", $name)));
|
$name = ucwords(strtolower(str_replace('_', ' ', $name)));
|
||||||
return str_replace(" ", "-", $name);
|
return str_replace(' ', '-', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -534,7 +534,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
|
|
||||||
// If not empty, the array MUST have all string keys.
|
// If not empty, the array MUST have all string keys.
|
||||||
$keys = array_keys($root);
|
$keys = array_keys($root);
|
||||||
if (count($keys) !== count(array_filter($keys, "is_string"))) {
|
if (count($keys) !== count(array_filter($keys, 'is_string'))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,17 @@ class Stream implements StreamInterface
|
||||||
* @param resource|string $resource A file system pointer resource or
|
* @param resource|string $resource A file system pointer resource or
|
||||||
* string
|
* string
|
||||||
*/
|
*/
|
||||||
public function __construct($resource = "")
|
public function __construct($resource = '')
|
||||||
{
|
{
|
||||||
if (is_resource($resource) && get_resource_type($resource) === "stream") {
|
if (is_resource($resource) && get_resource_type($resource) === 'stream') {
|
||||||
$this->resource = $resource;
|
$this->resource = $resource;
|
||||||
} elseif (is_string($resource)) {
|
} elseif (is_string($resource)) {
|
||||||
$this->resource = fopen("php://temp", "wb+");
|
$this->resource = fopen('php://temp', 'wb+');
|
||||||
if ($resource !== "") {
|
if ($resource !== '') {
|
||||||
$this->write($resource);
|
$this->write($resource);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException("Expected a resource handler.");
|
throw new \InvalidArgumentException('Expected a resource handler.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,8 +103,8 @@ class Stream implements StreamInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$statistics = fstat($this->resource);
|
$statistics = fstat($this->resource);
|
||||||
if ($statistics && $statistics["size"]) {
|
if ($statistics && $statistics['size']) {
|
||||||
return $statistics["size"];
|
return $statistics['size'];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -118,12 +118,12 @@ class Stream implements StreamInterface
|
||||||
public function tell()
|
public function tell()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to retrieve current position of detached stream.");
|
throw new \RuntimeException('Unable to retrieve current position of detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$position = ftell($this->resource);
|
$position = ftell($this->resource);
|
||||||
if ($position === false) {
|
if ($position === false) {
|
||||||
throw new \RuntimeException("Unable to retrieve current position of file pointer.");
|
throw new \RuntimeException('Unable to retrieve current position of file pointer.');
|
||||||
}
|
}
|
||||||
return $position;
|
return $position;
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +153,7 @@ class Stream implements StreamInterface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getMetadata("seekable") == 1;
|
return $this->getMetadata('seekable') == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -172,7 +172,7 @@ class Stream implements StreamInterface
|
||||||
public function seek($offset, $whence = SEEK_SET)
|
public function seek($offset, $whence = SEEK_SET)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to seek detached stream.");
|
throw new \RuntimeException('Unable to seek detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = -1;
|
$result = -1;
|
||||||
|
|
@ -180,7 +180,7 @@ class Stream implements StreamInterface
|
||||||
$result = fseek($this->resource, $offset, $whence);
|
$result = fseek($this->resource, $offset, $whence);
|
||||||
}
|
}
|
||||||
if ($result === -1) {
|
if ($result === -1) {
|
||||||
throw new \RuntimeException("Unable to seek to position.");
|
throw new \RuntimeException('Unable to seek to position.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ class Stream implements StreamInterface
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to seek detached stream.");
|
throw new \RuntimeException('Unable to seek detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -206,7 +206,7 @@ class Stream implements StreamInterface
|
||||||
$result = rewind($this->resource);
|
$result = rewind($this->resource);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException("Unable to rewind.");
|
throw new \RuntimeException('Unable to rewind.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,7 +235,7 @@ class Stream implements StreamInterface
|
||||||
public function write($string)
|
public function write($string)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to write to detached stream.");
|
throw new \RuntimeException('Unable to write to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -243,7 +243,7 @@ class Stream implements StreamInterface
|
||||||
$result = fwrite($this->resource, $string);
|
$result = fwrite($this->resource, $string);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException("Unable to write to stream.");
|
throw new \RuntimeException('Unable to write to stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
@ -276,7 +276,7 @@ class Stream implements StreamInterface
|
||||||
public function read($length)
|
public function read($length)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to read to detached stream.");
|
throw new \RuntimeException('Unable to read to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -284,7 +284,7 @@ class Stream implements StreamInterface
|
||||||
$result = fread($this->resource, $length);
|
$result = fread($this->resource, $length);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException("Unable to read from stream.");
|
throw new \RuntimeException('Unable to read from stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
@ -299,7 +299,7 @@ class Stream implements StreamInterface
|
||||||
public function getContents()
|
public function getContents()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException("Unable to read to detached stream.");
|
throw new \RuntimeException('Unable to read to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -307,7 +307,7 @@ class Stream implements StreamInterface
|
||||||
$result = stream_get_contents($this->resource);
|
$result = stream_get_contents($this->resource);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException("Unable to read from stream.");
|
throw new \RuntimeException('Unable to read from stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,13 @@ class UploadedFile implements UploadedFileInterface
|
||||||
public function getStream()
|
public function getStream()
|
||||||
{
|
{
|
||||||
if ($this->tmpName === null) {
|
if ($this->tmpName === null) {
|
||||||
throw new \RuntimeException("Unable to read uploaded file.");
|
throw new \RuntimeException('Unable to read uploaded file.');
|
||||||
}
|
}
|
||||||
if ($this->moved) {
|
if ($this->moved) {
|
||||||
throw new \RuntimeException("File has already been moved.");
|
throw new \RuntimeException('File has already been moved.');
|
||||||
}
|
}
|
||||||
if (php_sapi_name() !== "cli" && !is_uploaded_file($this->tmpName)) {
|
if (php_sapi_name() !== 'cli' && !is_uploaded_file($this->tmpName)) {
|
||||||
throw new \RuntimeException("File is not an uploaded file.");
|
throw new \RuntimeException('File is not an uploaded file.');
|
||||||
}
|
}
|
||||||
return $this->stream;
|
return $this->stream;
|
||||||
}
|
}
|
||||||
|
|
@ -124,9 +124,9 @@ class UploadedFile implements UploadedFileInterface
|
||||||
public function moveTo($path)
|
public function moveTo($path)
|
||||||
{
|
{
|
||||||
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
||||||
throw new \RuntimeException("File " . $this->tmpName . " does not exist.");
|
throw new \RuntimeException('File ' . $this->tmpName . ' does not exist.');
|
||||||
}
|
}
|
||||||
if (php_sapi_name() === "cli") {
|
if (php_sapi_name() === 'cli') {
|
||||||
rename($this->tmpName, $path);
|
rename($this->tmpName, $path);
|
||||||
} else {
|
} else {
|
||||||
move_uploaded_file($this->tmpName, $path);
|
move_uploaded_file($this->tmpName, $path);
|
||||||
|
|
|
||||||
|
|
@ -21,21 +21,21 @@ class Uri implements UriInterface
|
||||||
const MAX_PORT = 65535;
|
const MAX_PORT = 65535;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $scheme = "";
|
private $scheme = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $user = "";
|
private $user = '';
|
||||||
/** @var string|null */
|
/** @var string|null */
|
||||||
private $password;
|
private $password;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $host = "";
|
private $host = '';
|
||||||
/** @var int|null */
|
/** @var int|null */
|
||||||
private $port;
|
private $port;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $path = "";
|
private $path = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $query = "";
|
private $query = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $fragment = "";
|
private $fragment = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $uri A string representation of a URI.
|
* @param string $uri A string representation of a URI.
|
||||||
|
|
@ -112,15 +112,15 @@ class Uri implements UriInterface
|
||||||
*/
|
*/
|
||||||
public function getAuthority()
|
public function getAuthority()
|
||||||
{
|
{
|
||||||
$authority = "";
|
$authority = '';
|
||||||
|
|
||||||
$host = $this->getHost();
|
$host = $this->getHost();
|
||||||
if ($host !== "") {
|
if ($host !== '') {
|
||||||
|
|
||||||
// User Info
|
// User Info
|
||||||
$userInfo = $this->getUserInfo();
|
$userInfo = $this->getUserInfo();
|
||||||
if ($userInfo !== "") {
|
if ($userInfo !== '') {
|
||||||
$authority .= $userInfo . "@";
|
$authority .= $userInfo . '@';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host
|
// Host
|
||||||
|
|
@ -130,8 +130,8 @@ class Uri implements UriInterface
|
||||||
$port = $this->getPort();
|
$port = $this->getPort();
|
||||||
if ($port !== null) {
|
if ($port !== null) {
|
||||||
$scheme = $this->getScheme();
|
$scheme = $this->getScheme();
|
||||||
if (($scheme === "http" && $port !== 80) || ($scheme === "https" && $port !== 443)) {
|
if (($scheme === 'http' && $port !== 80) || ($scheme === 'https' && $port !== 443)) {
|
||||||
$authority .= ":" . $port;
|
$authority .= ':' . $port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +158,7 @@ class Uri implements UriInterface
|
||||||
{
|
{
|
||||||
$userInfo = $this->user;
|
$userInfo = $this->user;
|
||||||
if ($userInfo && $this->password) {
|
if ($userInfo && $this->password) {
|
||||||
$userInfo .= ":" . $this->password;
|
$userInfo .= ':' . $this->password;
|
||||||
}
|
}
|
||||||
return $userInfo;
|
return $userInfo;
|
||||||
}
|
}
|
||||||
|
|
@ -198,9 +198,9 @@ class Uri implements UriInterface
|
||||||
{
|
{
|
||||||
if ($this->port === null) {
|
if ($this->port === null) {
|
||||||
switch ($this->scheme) {
|
switch ($this->scheme) {
|
||||||
case "http":
|
case 'http':
|
||||||
return 80;
|
return 80;
|
||||||
case "https":
|
case 'https':
|
||||||
return 443;
|
return 443;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -236,7 +236,7 @@ class Uri implements UriInterface
|
||||||
*/
|
*/
|
||||||
public function getPath()
|
public function getPath()
|
||||||
{
|
{
|
||||||
if ($this->path === "*") {
|
if ($this->path === '*') {
|
||||||
return $this->path;
|
return $this->path;
|
||||||
}
|
}
|
||||||
return $this->percentEncode($this->path);
|
return $this->percentEncode($this->path);
|
||||||
|
|
@ -305,9 +305,9 @@ class Uri implements UriInterface
|
||||||
*/
|
*/
|
||||||
public function withScheme($scheme)
|
public function withScheme($scheme)
|
||||||
{
|
{
|
||||||
$scheme = $scheme ? strtolower($scheme) : "";
|
$scheme = $scheme ? strtolower($scheme) : '';
|
||||||
if (!in_array($scheme, ["", "http", "https"])) {
|
if (!in_array($scheme, ['', 'http', 'https'])) {
|
||||||
throw new \InvalidArgumentException("Scheme must be http, https, or empty.");
|
throw new \InvalidArgumentException('Scheme must be http, https, or empty.');
|
||||||
}
|
}
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
$uri->scheme = $scheme;
|
$uri->scheme = $scheme;
|
||||||
|
|
@ -351,7 +351,7 @@ class Uri implements UriInterface
|
||||||
public function withHost($host)
|
public function withHost($host)
|
||||||
{
|
{
|
||||||
if (!is_string($host)) {
|
if (!is_string($host)) {
|
||||||
throw new \InvalidArgumentException("Host must be a string.");
|
throw new \InvalidArgumentException('Host must be a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
|
|
@ -380,12 +380,12 @@ class Uri implements UriInterface
|
||||||
{
|
{
|
||||||
if (is_numeric($port)) {
|
if (is_numeric($port)) {
|
||||||
if ($port < self::MIN_PORT || $port > self::MAX_PORT) {
|
if ($port < self::MIN_PORT || $port > self::MAX_PORT) {
|
||||||
$message = sprintf("Port must be between %s and %s.", self::MIN_PORT, self::MAX_PORT);
|
$message = sprintf('Port must be between %s and %s.', self::MIN_PORT, self::MAX_PORT);
|
||||||
throw new \InvalidArgumentException($message);
|
throw new \InvalidArgumentException($message);
|
||||||
}
|
}
|
||||||
$port = (int) $port;
|
$port = (int) $port;
|
||||||
} elseif ($port !== null) {
|
} elseif ($port !== null) {
|
||||||
throw new \InvalidArgumentException("Port must be an int or null.");
|
throw new \InvalidArgumentException('Port must be an int or null.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
|
|
@ -413,7 +413,7 @@ class Uri implements UriInterface
|
||||||
public function withPath($path)
|
public function withPath($path)
|
||||||
{
|
{
|
||||||
if (!is_string($path)) {
|
if (!is_string($path)) {
|
||||||
throw new \InvalidArgumentException("Path must be a string");
|
throw new \InvalidArgumentException('Path must be a string');
|
||||||
}
|
}
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
$uri->path = $path;
|
$uri->path = $path;
|
||||||
|
|
@ -488,29 +488,29 @@ class Uri implements UriInterface
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$string = "";
|
$string = '';
|
||||||
|
|
||||||
$authority = $this->getAuthority();
|
$authority = $this->getAuthority();
|
||||||
if ($authority !== "") {
|
if ($authority !== '') {
|
||||||
$scheme = $this->getScheme();
|
$scheme = $this->getScheme();
|
||||||
if ($scheme !== "") {
|
if ($scheme !== '') {
|
||||||
$string = $scheme . ":";
|
$string = $scheme . ':';
|
||||||
}
|
}
|
||||||
$string .= "//$authority";
|
$string .= "//$authority";
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $this->getPath();
|
$path = $this->getPath();
|
||||||
if ($path !== "") {
|
if ($path !== '') {
|
||||||
$string .= $path;
|
$string .= $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->getQuery();
|
$query = $this->getQuery();
|
||||||
if ($query !== "") {
|
if ($query !== '') {
|
||||||
$string .= "?$query";
|
$string .= "?$query";
|
||||||
}
|
}
|
||||||
|
|
||||||
$fragment = $this->getFragment();
|
$fragment = $this->getFragment();
|
||||||
if ($fragment !== "") {
|
if ($fragment !== '') {
|
||||||
$string .= "#$fragment";
|
$string .= "#$fragment";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ class MethodMap
|
||||||
*/
|
*/
|
||||||
public function register($method, $dispatchable): void
|
public function register($method, $dispatchable): void
|
||||||
{
|
{
|
||||||
$methods = explode(",", $method);
|
$methods = explode(',', $method);
|
||||||
$methods = array_map("trim", $methods);
|
$methods = array_map('trim', $methods);
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
$this->map[$method] = $dispatchable;
|
$this->map[$method] = $dispatchable;
|
||||||
}
|
}
|
||||||
|
|
@ -71,18 +71,18 @@ class MethodMap
|
||||||
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
||||||
}
|
}
|
||||||
// For HEAD, dispatch GET by default.
|
// For HEAD, dispatch GET by default.
|
||||||
if ($method === "HEAD" && isset($this->map["GET"])) {
|
if ($method === 'HEAD' && isset($this->map['GET'])) {
|
||||||
$middleware = $this->map["GET"];
|
$middleware = $this->map['GET'];
|
||||||
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
||||||
}
|
}
|
||||||
// Dispatch * middleware, if registered.
|
// Dispatch * middleware, if registered.
|
||||||
if (isset($this->map["*"])) {
|
if (isset($this->map['*'])) {
|
||||||
$middleware = $this->map["*"];
|
$middleware = $this->map['*'];
|
||||||
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
return $this->dispatchMiddleware($middleware, $request, $response, $next);
|
||||||
}
|
}
|
||||||
// Respond describing the allowed methods, either as a 405 response or
|
// Respond describing the allowed methods, either as a 405 response or
|
||||||
// in response to an OPTIONS request.
|
// in response to an OPTIONS request.
|
||||||
if ($method === "OPTIONS") {
|
if ($method === 'OPTIONS') {
|
||||||
$response = $response->withStatus(200);
|
$response = $response->withStatus(200);
|
||||||
} else {
|
} else {
|
||||||
$response = $response->withStatus(405);
|
$response = $response->withStatus(405);
|
||||||
|
|
@ -94,8 +94,8 @@ class MethodMap
|
||||||
|
|
||||||
private function addAllowHeader(ResponseInterface $response): ResponseInterface
|
private function addAllowHeader(ResponseInterface $response): ResponseInterface
|
||||||
{
|
{
|
||||||
$methods = join(",", $this->getAllowedMethods());
|
$methods = join(',', $this->getAllowedMethods());
|
||||||
return $response->withHeader("Allow", $methods);
|
return $response->withHeader('Allow', $methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,12 +105,12 @@ class MethodMap
|
||||||
{
|
{
|
||||||
$methods = array_keys($this->map);
|
$methods = array_keys($this->map);
|
||||||
// Add HEAD if GET is allowed and HEAD is not present.
|
// Add HEAD if GET is allowed and HEAD is not present.
|
||||||
if (in_array("GET", $methods) && !in_array("HEAD", $methods)) {
|
if (in_array('GET', $methods) && !in_array('HEAD', $methods)) {
|
||||||
$methods[] = "HEAD";
|
$methods[] = 'HEAD';
|
||||||
}
|
}
|
||||||
// Add OPTIONS if not already present.
|
// Add OPTIONS if not already present.
|
||||||
if (!in_array("OPTIONS", $methods)) {
|
if (!in_array('OPTIONS', $methods)) {
|
||||||
$methods[] = "OPTIONS";
|
$methods[] = 'OPTIONS';
|
||||||
}
|
}
|
||||||
return $methods;
|
return $methods;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class PrefixRoute extends Route
|
||||||
{
|
{
|
||||||
public function __construct(string $target, MethodMap $methodMap)
|
public function __construct(string $target, MethodMap $methodMap)
|
||||||
{
|
{
|
||||||
parent::__construct(rtrim($target, "*"), $methodMap);
|
parent::__construct(rtrim($target, '*'), $methodMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType(): int
|
public function getType(): int
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class RegexRoute extends Route
|
||||||
$this->captures = $captures;
|
$this->captures = $captures;
|
||||||
return true;
|
return true;
|
||||||
} elseif ($matched === false) {
|
} elseif ($matched === false) {
|
||||||
throw new \RuntimeException("Invalid regular expression: " . $this->getTarget());
|
throw new \RuntimeException('Invalid regular expression: ' . $this->getTarget());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ class RouteFactory implements RouteFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function create($target)
|
public function create($target)
|
||||||
{
|
{
|
||||||
if ($target[0] === "/") {
|
if ($target[0] === '/') {
|
||||||
|
|
||||||
// Possible static, prefix, or template
|
// Possible static, prefix, or template
|
||||||
|
|
||||||
// PrefixRoutes end with *
|
// PrefixRoutes end with *
|
||||||
if (substr($target, -1) === "*") {
|
if (substr($target, -1) === '*') {
|
||||||
return new PrefixRoute($target, new MethodMap($this->dispatcher));
|
return new PrefixRoute($target, new MethodMap($this->dispatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class TemplateRoute extends Route
|
||||||
|
|
||||||
private function matchesStartOfRequestTarget(string $requestTarget): bool
|
private function matchesStartOfRequestTarget(string $requestTarget): bool
|
||||||
{
|
{
|
||||||
$firstVarPos = strpos($this->target, "{");
|
$firstVarPos = strpos($this->target, '{');
|
||||||
if ($firstVarPos === false) {
|
if ($firstVarPos === false) {
|
||||||
return $requestTarget === $this->target;
|
return $requestTarget === $this->target;
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +65,7 @@ class TemplateRoute extends Route
|
||||||
$variables = [];
|
$variables = [];
|
||||||
|
|
||||||
// Isolate the named captures.
|
// Isolate the named captures.
|
||||||
$keys = array_filter(array_keys($matches), "is_string");
|
$keys = array_filter(array_keys($matches), 'is_string');
|
||||||
|
|
||||||
// Store named captures to the variables.
|
// Store named captures to the variables.
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
|
|
@ -73,7 +73,7 @@ class TemplateRoute extends Route
|
||||||
|
|
||||||
if (isset($this->explosions[$key])) {
|
if (isset($this->explosions[$key])) {
|
||||||
$values = explode($this->explosions[$key], $value);
|
$values = explode($this->explosions[$key], $value);
|
||||||
$variables[$key] = array_map("urldecode", $values);
|
$variables[$key] = array_map('urldecode', $values);
|
||||||
} else {
|
} else {
|
||||||
$value = urldecode($value);
|
$value = urldecode($value);
|
||||||
$variables[$key] = $value;
|
$variables[$key] = $value;
|
||||||
|
|
@ -90,16 +90,16 @@ class TemplateRoute extends Route
|
||||||
|
|
||||||
// Escape allowable characters with regex meaning.
|
// Escape allowable characters with regex meaning.
|
||||||
$escape = [
|
$escape = [
|
||||||
"." => "\\.",
|
'.' => '\\.',
|
||||||
"-" => "\\-",
|
'-' => '\\-',
|
||||||
"+" => "\\+",
|
'+' => '\\+',
|
||||||
"*" => "\\*"
|
'*' => '\\*'
|
||||||
];
|
];
|
||||||
$pattern = str_replace(array_keys($escape), array_values($escape), $pattern);
|
$pattern = str_replace(array_keys($escape), array_values($escape), $pattern);
|
||||||
$unescape = [
|
$unescape = [
|
||||||
"{\\+" => "{+",
|
'{\\+' => '{+',
|
||||||
"{\\." => "{.",
|
'{\\.' => '{.',
|
||||||
"\\*}" => "*}"
|
'\\*}' => '*}'
|
||||||
];
|
];
|
||||||
$pattern = str_replace(array_keys($unescape), array_values($unescape), $pattern);
|
$pattern = str_replace(array_keys($unescape), array_values($unescape), $pattern);
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ class TemplateRoute extends Route
|
||||||
|
|
||||||
$pattern = preg_replace_callback(
|
$pattern = preg_replace_callback(
|
||||||
self::URI_TEMPLATE_EXPRESSION_RE,
|
self::URI_TEMPLATE_EXPRESSION_RE,
|
||||||
[$this, "uriVariableReplacementCallback"],
|
[$this, 'uriVariableReplacementCallback'],
|
||||||
$pattern
|
$pattern
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -120,35 +120,35 @@ class TemplateRoute extends Route
|
||||||
$name = $matches[1];
|
$name = $matches[1];
|
||||||
$pattern = self::RE_UNRESERVED;
|
$pattern = self::RE_UNRESERVED;
|
||||||
|
|
||||||
$prefix = "";
|
$prefix = '';
|
||||||
$delimiter = ",";
|
$delimiter = ',';
|
||||||
$explodeDelimiter = ",";
|
$explodeDelimiter = ',';
|
||||||
|
|
||||||
// Read the first character as an operator. This determines which
|
// Read the first character as an operator. This determines which
|
||||||
// characters to allow in the match.
|
// characters to allow in the match.
|
||||||
$operator = $name[0];
|
$operator = $name[0];
|
||||||
|
|
||||||
// Read the last character as the modifier.
|
// Read the last character as the modifier.
|
||||||
$explosion = (substr($name, -1, 1) === "*");
|
$explosion = (substr($name, -1, 1) === '*');
|
||||||
|
|
||||||
switch ($operator) {
|
switch ($operator) {
|
||||||
case "+":
|
case '+':
|
||||||
$name = substr($name, 1);
|
$name = substr($name, 1);
|
||||||
$pattern = ".*";
|
$pattern = '.*';
|
||||||
break;
|
break;
|
||||||
case ".":
|
case '.':
|
||||||
$name = substr($name, 1);
|
$name = substr($name, 1);
|
||||||
$prefix = "\\.";
|
$prefix = '\\.';
|
||||||
$delimiter = "\\.";
|
$delimiter = '\\.';
|
||||||
$explodeDelimiter = ".";
|
$explodeDelimiter = '.';
|
||||||
break;
|
break;
|
||||||
case "/":
|
case '/':
|
||||||
$name = substr($name, 1);
|
$name = substr($name, 1);
|
||||||
$prefix = "\\/";
|
$prefix = '\\/';
|
||||||
$delimiter = "\\/";
|
$delimiter = '\\/';
|
||||||
if ($explosion) {
|
if ($explosion) {
|
||||||
$pattern = '[0-9a-zA-Z\-._\~%,\/]*'; // Unreserved + "," and "/"
|
$pattern = '[0-9a-zA-Z\-._\~%,\/]*'; // Unreserved + "," and "/"
|
||||||
$explodeDelimiter = "/";
|
$explodeDelimiter = '/';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +162,7 @@ class TemplateRoute extends Route
|
||||||
$this->explosions[$name] = $explodeDelimiter;
|
$this->explosions[$name] = $explodeDelimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = explode(",", $name);
|
$names = explode(',', $name);
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
$results[] = "(?<{$name}>{$pattern})";
|
$results[] = "(?<{$name}>{$pattern})";
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ class Router
|
||||||
$this->staticRoutes[$route->getTarget()] = $route;
|
$this->staticRoutes[$route->getTarget()] = $route;
|
||||||
break;
|
break;
|
||||||
case RouteInterface::TYPE_PREFIX:
|
case RouteInterface::TYPE_PREFIX:
|
||||||
$this->prefixRoutes[rtrim($route->getTarget(), "*")] = $route;
|
$this->prefixRoutes[rtrim($route->getTarget(), '*')] = $route;
|
||||||
break;
|
break;
|
||||||
case RouteInterface::TYPE_PATTERN:
|
case RouteInterface::TYPE_PATTERN:
|
||||||
$this->patternRoutes[] = $route;
|
$this->patternRoutes[] = $route;
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,12 @@ class Transmitter implements TransmitterInterface
|
||||||
// - Response does not have a Transfer-encoding: chunked header
|
// - Response does not have a Transfer-encoding: chunked header
|
||||||
// - Response body stream is readable and reports a non-null size
|
// - Response body stream is readable and reports a non-null size
|
||||||
//
|
//
|
||||||
if (!$response->hasHeader("Content-length")
|
if (!$response->hasHeader('Content-length')
|
||||||
&& !(strtolower($response->getHeaderLine("Transfer-encoding")) === "chunked")
|
&& !(strtolower($response->getHeaderLine('Transfer-encoding')) === 'chunked')
|
||||||
) {
|
) {
|
||||||
$size = $response->getBody()->getSize();
|
$size = $response->getBody()->getSize();
|
||||||
if ($size !== null) {
|
if ($size !== null) {
|
||||||
$response = $response->withHeader("Content-length", (string) $size);
|
$response = $response->withHeader('Content-length', (string) $size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,19 @@ class DispatchStackTest extends TestCase
|
||||||
$callOrder = [];
|
$callOrder = [];
|
||||||
$stack = new DispatchStack(new Dispatcher());
|
$stack = new DispatchStack(new Dispatcher());
|
||||||
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
||||||
$callOrder[] = "first";
|
$callOrder[] = 'first';
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
});
|
});
|
||||||
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
||||||
$callOrder[] = "second";
|
$callOrder[] = 'second';
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
});
|
});
|
||||||
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
$stack->add(function ($request, $response, $next) use (&$callOrder) {
|
||||||
$callOrder[] = "third";
|
$callOrder[] = 'third';
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
});
|
});
|
||||||
$stack($this->request, $this->response, $this->next);
|
$stack($this->request, $this->response, $this->next);
|
||||||
$this->assertEquals(["first", "second", "third"], $callOrder);
|
$this->assertEquals(['first', 'second', 'third'], $callOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCallsNextAfterDispatchingEmptyStack()
|
public function testCallsNextAfterDispatchingEmptyStack()
|
||||||
|
|
|
||||||
|
|
@ -10,57 +10,57 @@ class HeaderCollectionTest extends TestCase
|
||||||
public function testAddsSingleHeaderAndIndicatesCaseInsensitiveIsset()
|
public function testAddsSingleHeaderAndIndicatesCaseInsensitiveIsset()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Content-Type"] = "application/json";
|
$collection['Content-Type'] = 'application/json';
|
||||||
$this->assertTrue(isset($collection["content-type"]));
|
$this->assertTrue(isset($collection['content-type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddsMultipleHeadersAndIndicatesCaseInsensitiveIsset()
|
public function testAddsMultipleHeadersAndIndicatesCaseInsensitiveIsset()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
$collection["SET-COOKIE"] = "dog=Bear";
|
$collection['SET-COOKIE'] = 'dog=Bear';
|
||||||
$this->assertTrue(isset($collection["set-cookie"]));
|
$this->assertTrue(isset($collection['set-cookie']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnsHeadersWithCaseInsensitiveHeaderName()
|
public function testReturnsHeadersWithCaseInsensitiveHeaderName()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
$collection["SET-COOKIE"] = "dog=Bear";
|
$collection['SET-COOKIE'] = 'dog=Bear';
|
||||||
|
|
||||||
$headers = $collection["set-cookie"];
|
$headers = $collection['set-cookie'];
|
||||||
$this->assertEquals(2, count(array_intersect($headers, ["cat=Molly", "dog=Bear"])));
|
$this->assertEquals(2, count(array_intersect($headers, ['cat=Molly', 'dog=Bear'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemovesHeadersWithCaseInsensitiveHeaderName()
|
public function testRemovesHeadersWithCaseInsensitiveHeaderName()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
$collection["SET-COOKIE"] = "dog=Bear";
|
$collection['SET-COOKIE'] = 'dog=Bear';
|
||||||
unset($collection["set-cookie"]);
|
unset($collection['set-cookie']);
|
||||||
$this->assertFalse(isset($collection["set-cookie"]));
|
$this->assertFalse(isset($collection['set-cookie']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @coversNothing */
|
/** @coversNothing */
|
||||||
public function testCloneMakesDeepCopyOfHeaders()
|
public function testCloneMakesDeepCopyOfHeaders()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
|
|
||||||
$clone = clone $collection;
|
$clone = clone $collection;
|
||||||
unset($clone["Set-Cookie"]);
|
unset($clone['Set-Cookie']);
|
||||||
|
|
||||||
$this->assertTrue(isset($collection["set-cookie"]) && !isset($clone["set-cookie"]));
|
$this->assertTrue(isset($collection['set-cookie']) && !isset($clone['set-cookie']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIteratesWithOriginalKeys()
|
public function testIteratesWithOriginalKeys()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Content-length"] = "100";
|
$collection['Content-length'] = '100';
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
$collection["Set-Cookie"] = "dog=Bear";
|
$collection['Set-Cookie'] = 'dog=Bear';
|
||||||
$collection["Content-type"] = "application/json";
|
$collection['Content-type'] = 'application/json';
|
||||||
unset($collection["Content-length"]);
|
unset($collection['Content-length']);
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ class HeaderCollectionTest extends TestCase
|
||||||
$headers[] = $key;
|
$headers[] = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
$expected = ["Content-type", "Set-Cookie"];
|
$expected = ['Content-type', 'Set-Cookie'];
|
||||||
|
|
||||||
$countUnmatched = count(array_diff($expected, $headers)) + count(array_diff($headers, $expected));
|
$countUnmatched = count(array_diff($expected, $headers)) + count(array_diff($headers, $expected));
|
||||||
$this->assertEquals(0, $countUnmatched);
|
$this->assertEquals(0, $countUnmatched);
|
||||||
|
|
@ -77,11 +77,11 @@ class HeaderCollectionTest extends TestCase
|
||||||
public function testIteratesWithOriginalKeysAndValues()
|
public function testIteratesWithOriginalKeysAndValues()
|
||||||
{
|
{
|
||||||
$collection = new HeaderCollection();
|
$collection = new HeaderCollection();
|
||||||
$collection["Content-length"] = "100";
|
$collection['Content-length'] = '100';
|
||||||
$collection["Set-Cookie"] = "cat=Molly";
|
$collection['Set-Cookie'] = 'cat=Molly';
|
||||||
$collection["Set-Cookie"] = "dog=Bear";
|
$collection['Set-Cookie'] = 'dog=Bear';
|
||||||
$collection["Content-type"] = "application/json";
|
$collection['Content-type'] = 'application/json';
|
||||||
unset($collection["Content-length"]);
|
unset($collection['Content-length']);
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
|
|
||||||
|
|
@ -96,8 +96,8 @@ class HeaderCollectionTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
$expected = [
|
$expected = [
|
||||||
"Set-Cookie" => ["cat=Molly", "dog=Bear"],
|
'Set-Cookie' => ['cat=Molly', 'dog=Bear'],
|
||||||
"Content-type" => ["application/json"]
|
'Content-type' => ['application/json']
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertEquals($expected, $headers);
|
$this->assertEquals($expected, $headers);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class NullStreamTest extends TestCase
|
||||||
public function testCastsToString()
|
public function testCastsToString()
|
||||||
{
|
{
|
||||||
$stream = new NullStream();
|
$stream = new NullStream();
|
||||||
$this->assertEquals("", (string) $stream);
|
$this->assertEquals('', (string) $stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCloseDoesNothing()
|
public function testCloseDoesNothing()
|
||||||
|
|
@ -75,7 +75,7 @@ class NullStreamTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$stream = new NullStream();
|
$stream = new NullStream();
|
||||||
$stream->write("");
|
$stream->write('');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsReadableReturnsTrue()
|
public function testIsReadableReturnsTrue()
|
||||||
|
|
@ -87,13 +87,13 @@ class NullStreamTest extends TestCase
|
||||||
public function testReadReturnsEmptyString()
|
public function testReadReturnsEmptyString()
|
||||||
{
|
{
|
||||||
$stream = new NullStream();
|
$stream = new NullStream();
|
||||||
$this->assertEquals("", $stream->read(100));
|
$this->assertEquals('', $stream->read(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetContentsReturnsEmptyString()
|
public function testGetContentsReturnsEmptyString()
|
||||||
{
|
{
|
||||||
$stream = new NullStream();
|
$stream = new NullStream();
|
||||||
$this->assertEquals("", $stream->getContents());
|
$this->assertEquals('', $stream->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMetadataReturnsNull()
|
public function testGetMetadataReturnsNull()
|
||||||
|
|
@ -105,6 +105,6 @@ class NullStreamTest extends TestCase
|
||||||
public function testGetMetadataReturnsNullWithKey()
|
public function testGetMetadataReturnsNullWithKey()
|
||||||
{
|
{
|
||||||
$stream = new NullStream();
|
$stream = new NullStream();
|
||||||
$this->assertNull($stream->getMetadata("size"));
|
$this->assertNull($stream->getMetadata('size'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ class RequestTest extends TestCase
|
||||||
public function testGetRequestTargetPrefersExplicitRequestTarget()
|
public function testGetRequestTargetPrefersExplicitRequestTarget()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withRequestTarget("*");
|
$request = $request->withRequestTarget('*');
|
||||||
$this->assertEquals("*", $request->getRequestTarget());
|
$this->assertEquals('*', $request->getRequestTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRequestTargetUsesOriginFormOfUri()
|
public function testGetRequestTargetUsesOriginFormOfUri()
|
||||||
|
|
@ -70,20 +70,20 @@ class RequestTest extends TestCase
|
||||||
$uri = new Uri('/my/path?cat=Molly&dog=Bear');
|
$uri = new Uri('/my/path?cat=Molly&dog=Bear');
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withUri($uri);
|
$request = $request->withUri($uri);
|
||||||
$this->assertEquals("/my/path?cat=Molly&dog=Bear", $request->getRequestTarget());
|
$this->assertEquals('/my/path?cat=Molly&dog=Bear', $request->getRequestTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRequestTargetReturnsSlashByDefault()
|
public function testGetRequestTargetReturnsSlashByDefault()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$this->assertEquals("/", $request->getRequestTarget());
|
$this->assertEquals('/', $request->getRequestTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithRequestTargetCreatesNewInstance()
|
public function testWithRequestTargetCreatesNewInstance()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withRequestTarget("*");
|
$request = $request->withRequestTarget('*');
|
||||||
$this->assertEquals("*", $request->getRequestTarget());
|
$this->assertEquals('*', $request->getRequestTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -92,14 +92,14 @@ class RequestTest extends TestCase
|
||||||
public function testGetMethodReturnsGetByDefault()
|
public function testGetMethodReturnsGetByDefault()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$this->assertEquals("GET", $request->getMethod());
|
$this->assertEquals('GET', $request->getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithMethodCreatesNewInstance()
|
public function testWithMethodCreatesNewInstance()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withMethod("POST");
|
$request = $request->withMethod('POST');
|
||||||
$this->assertEquals("POST", $request->getMethod());
|
$this->assertEquals('POST', $request->getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,7 +117,7 @@ class RequestTest extends TestCase
|
||||||
return [
|
return [
|
||||||
[0],
|
[0],
|
||||||
[false],
|
[false],
|
||||||
["WITH SPACE"]
|
['WITH SPACE']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,44 +146,44 @@ class RequestTest extends TestCase
|
||||||
|
|
||||||
$request1 = new Request();
|
$request1 = new Request();
|
||||||
$request1 = $request1->withUri($uri1);
|
$request1 = $request1->withUri($uri1);
|
||||||
$request1 = $request1->withHeader("Accept", "application/json");
|
$request1 = $request1->withHeader('Accept', 'application/json');
|
||||||
|
|
||||||
$request2 = $request1->withUri($uri2);
|
$request2 = $request1->withUri($uri2);
|
||||||
$request2 = $request2->withHeader("Accept", "text/plain");
|
$request2 = $request2->withHeader('Accept', 'text/plain');
|
||||||
|
|
||||||
$this->assertNotEquals($request1->getHeader("Accept"), $request2->getHeader("Accept"));
|
$this->assertNotEquals($request1->getHeader('Accept'), $request2->getHeader('Accept'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithUriUpdatesHostHeader()
|
public function testWithUriUpdatesHostHeader()
|
||||||
{
|
{
|
||||||
$hostname = "bar.com";
|
$hostname = 'bar.com';
|
||||||
$uri = new uri("http://$hostname");
|
$uri = new uri("http://$hostname");
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withHeader("Host", "foo.com");
|
$request = $request->withHeader('Host', 'foo.com');
|
||||||
$request = $request->withUri($uri);
|
$request = $request->withUri($uri);
|
||||||
$this->assertSame([$hostname], $request->getHeader("Host"));
|
$this->assertSame([$hostname], $request->getHeader('Host'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithUriDoesNotUpdatesHostHeaderWhenUriHasNoHost()
|
public function testWithUriDoesNotUpdatesHostHeaderWhenUriHasNoHost()
|
||||||
{
|
{
|
||||||
$hostname = "foo.com";
|
$hostname = 'foo.com';
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withHeader("Host", $hostname);
|
$request = $request->withHeader('Host', $hostname);
|
||||||
$request = $request->withUri($uri);
|
$request = $request->withUri($uri);
|
||||||
$this->assertSame([$hostname], $request->getHeader("Host"));
|
$this->assertSame([$hostname], $request->getHeader('Host'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPreserveHostUpdatesHostHeaderWhenHeaderIsOriginallyMissing()
|
public function testPreserveHostUpdatesHostHeaderWhenHeaderIsOriginallyMissing()
|
||||||
{
|
{
|
||||||
$hostname = "foo.com";
|
$hostname = 'foo.com';
|
||||||
$uri = new uri("http://$hostname");
|
$uri = new uri("http://$hostname");
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withUri($uri, true);
|
$request = $request->withUri($uri, true);
|
||||||
$this->assertSame([$hostname], $request->getHeader("Host"));
|
$this->assertSame([$hostname], $request->getHeader('Host'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPreserveHostDoesNotUpdatesWhenBothAreMissingHosts()
|
public function testPreserveHostDoesNotUpdatesWhenBothAreMissingHosts()
|
||||||
|
|
@ -192,17 +192,17 @@ class RequestTest extends TestCase
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withUri($uri, true);
|
$request = $request->withUri($uri, true);
|
||||||
$this->assertSame([], $request->getHeader("Host"));
|
$this->assertSame([], $request->getHeader('Host'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPreserveHostDoesNotUpdateHostHeader()
|
public function testPreserveHostDoesNotUpdateHostHeader()
|
||||||
{
|
{
|
||||||
$hostname = "foo.com";
|
$hostname = 'foo.com';
|
||||||
$uri = new uri("http://bar.com");
|
$uri = new uri('http://bar.com');
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request = $request->withHeader("Host", $hostname);
|
$request = $request->withHeader('Host', $hostname);
|
||||||
$request = $request->withUri($uri, true);
|
$request = $request->withUri($uri, true);
|
||||||
$this->assertSame([$hostname], $request->getHeader("Host"));
|
$this->assertSame([$hostname], $request->getHeader('Host'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ class ResponseTest extends TestCase
|
||||||
public function testSetsHeadersOnConstruction()
|
public function testSetsHeadersOnConstruction()
|
||||||
{
|
{
|
||||||
$response = new Response(200, [
|
$response = new Response(200, [
|
||||||
"X-foo" => ["bar","baz"]
|
'X-foo' => ['bar','baz']
|
||||||
]);
|
]);
|
||||||
$this->assertEquals(["bar","baz"], $response->getHeader("X-foo"));
|
$this->assertEquals(['bar','baz'], $response->getHeader('X-foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetsBodyOnConstruction()
|
public function testSetsBodyOnConstruction()
|
||||||
|
|
@ -53,45 +53,45 @@ class ResponseTest extends TestCase
|
||||||
public function statusProvider()
|
public function statusProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[100, null, "Continue"],
|
[100, null, 'Continue'],
|
||||||
[101, null, "Switching Protocols"],
|
[101, null, 'Switching Protocols'],
|
||||||
[200, null, "OK"],
|
[200, null, 'OK'],
|
||||||
[201, null, "Created"],
|
[201, null, 'Created'],
|
||||||
[202, null, "Accepted"],
|
[202, null, 'Accepted'],
|
||||||
[203, null, "Non-Authoritative Information"],
|
[203, null, 'Non-Authoritative Information'],
|
||||||
[204, null, "No Content"],
|
[204, null, 'No Content'],
|
||||||
[205, null, "Reset Content"],
|
[205, null, 'Reset Content'],
|
||||||
[206, null, "Partial Content"],
|
[206, null, 'Partial Content'],
|
||||||
[300, null, "Multiple Choices"],
|
[300, null, 'Multiple Choices'],
|
||||||
[301, null, "Moved Permanently"],
|
[301, null, 'Moved Permanently'],
|
||||||
[302, null, "Found"],
|
[302, null, 'Found'],
|
||||||
[303, null, "See Other"],
|
[303, null, 'See Other'],
|
||||||
[304, null, "Not Modified"],
|
[304, null, 'Not Modified'],
|
||||||
[305, null, "Use Proxy"],
|
[305, null, 'Use Proxy'],
|
||||||
[400, null, "Bad Request"],
|
[400, null, 'Bad Request'],
|
||||||
[401, null, "Unauthorized"],
|
[401, null, 'Unauthorized'],
|
||||||
[402, null, "Payment Required"],
|
[402, null, 'Payment Required'],
|
||||||
[403, null, "Forbidden"],
|
[403, null, 'Forbidden'],
|
||||||
[404, null, "Not Found"],
|
[404, null, 'Not Found'],
|
||||||
[405, null, "Method Not Allowed"],
|
[405, null, 'Method Not Allowed'],
|
||||||
[406, null, "Not Acceptable"],
|
[406, null, 'Not Acceptable'],
|
||||||
[407, null, "Proxy Authentication Required"],
|
[407, null, 'Proxy Authentication Required'],
|
||||||
[408, null, "Request Timeout"],
|
[408, null, 'Request Timeout'],
|
||||||
[409, null, "Conflict"],
|
[409, null, 'Conflict'],
|
||||||
[410, null, "Gone"],
|
[410, null, 'Gone'],
|
||||||
[411, null, "Length Required"],
|
[411, null, 'Length Required'],
|
||||||
[412, null, "Precondition Failed"],
|
[412, null, 'Precondition Failed'],
|
||||||
[413, null, "Payload Too Large"],
|
[413, null, 'Payload Too Large'],
|
||||||
[414, null, "URI Too Long"],
|
[414, null, 'URI Too Long'],
|
||||||
[415, null, "Unsupported Media Type"],
|
[415, null, 'Unsupported Media Type'],
|
||||||
[500, null, "Internal Server Error"],
|
[500, null, 'Internal Server Error'],
|
||||||
[501, null, "Not Implemented"],
|
[501, null, 'Not Implemented'],
|
||||||
[502, null, "Bad Gateway"],
|
[502, null, 'Bad Gateway'],
|
||||||
[503, null, "Service Unavailable"],
|
[503, null, 'Service Unavailable'],
|
||||||
[504, null, "Gateway Timeout"],
|
[504, null, 'Gateway Timeout'],
|
||||||
[505, null, "HTTP Version Not Supported"],
|
[505, null, 'HTTP Version Not Supported'],
|
||||||
[598, null, ""],
|
[598, null, ''],
|
||||||
[599, "Nonstandard", "Nonstandard"]
|
[599, 'Nonstandard', 'Nonstandard']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,11 +99,11 @@ class ResponseTest extends TestCase
|
||||||
{
|
{
|
||||||
$response1 = new Response();
|
$response1 = new Response();
|
||||||
$response1 = $response1->withStatus(200);
|
$response1 = $response1->withStatus(200);
|
||||||
$response1 = $response1->withHeader("Content-type", "application/json");
|
$response1 = $response1->withHeader('Content-type', 'application/json');
|
||||||
|
|
||||||
$response2 = $response1->withStatus(404);
|
$response2 = $response1->withStatus(404);
|
||||||
$response2 = $response2->withHeader("Content-type", "text/plain");
|
$response2 = $response2->withHeader('Content-type', 'text/plain');
|
||||||
|
|
||||||
$this->assertNotEquals($response1->getStatusCode(), $response2->getHeader("Content-type"));
|
$this->assertNotEquals($response1->getStatusCode(), $response2->getHeader('Content-type'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,19 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsFromRequest()
|
public function testGetServerRequestReadsFromRequest()
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"HTTP_ACCEPT" => "application/json",
|
'HTTP_ACCEPT' => 'application/json',
|
||||||
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded",
|
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
||||||
"QUERY_STRING" => "guinea_pig=Claude&hamster=Fizzgig"
|
'QUERY_STRING' => 'guinea_pig=Claude&hamster=Fizzgig'
|
||||||
];
|
];
|
||||||
$_COOKIE = [
|
$_COOKIE = [
|
||||||
"cat" => "Molly"
|
'cat' => 'Molly'
|
||||||
];
|
];
|
||||||
$_FILES = [];
|
$_FILES = [];
|
||||||
$_POST = [
|
$_POST = [
|
||||||
"dog" => "Bear"
|
'dog' => 'Bear'
|
||||||
];
|
];
|
||||||
$attributes = ["guinea_pig" => "Claude"];
|
$attributes = ['guinea_pig' => 'Claude'];
|
||||||
$request = ServerRequest::getServerRequest($attributes);
|
$request = ServerRequest::getServerRequest($attributes);
|
||||||
$this->assertNotNull($request);
|
$this->assertNotNull($request);
|
||||||
return $request;
|
return $request;
|
||||||
|
|
@ -46,9 +46,9 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsProtocolVersion($expectedProtocol, $serverProtocol)
|
public function testGetServerRequestReadsProtocolVersion($expectedProtocol, $serverProtocol)
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"SERVER_PROTOCOL" => $serverProtocol,
|
'SERVER_PROTOCOL' => $serverProtocol,
|
||||||
"REQUEST_METHOD" => "GET"
|
'REQUEST_METHOD' => 'GET'
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertEquals($expectedProtocol, $request->getProtocolVersion());
|
$this->assertEquals($expectedProtocol, $request->getProtocolVersion());
|
||||||
|
|
@ -57,10 +57,10 @@ class ServerRequestTest extends TestCase
|
||||||
public function protocolVersionProvider()
|
public function protocolVersionProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["1.1", "HTTP/1.1"],
|
['1.1', 'HTTP/1.1'],
|
||||||
["1.0", "HTTP/1.0"],
|
['1.0', 'HTTP/1.0'],
|
||||||
["1.1", null],
|
['1.1', null],
|
||||||
["1.1", "INVALID"]
|
['1.1', 'INVALID']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,8 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsMethod($expectedMethod, $serverMethod)
|
public function testGetServerRequestReadsMethod($expectedMethod, $serverMethod)
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"REQUEST_METHOD" => $serverMethod
|
'REQUEST_METHOD' => $serverMethod
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertEquals($expectedMethod, $request->getMethod());
|
$this->assertEquals($expectedMethod, $request->getMethod());
|
||||||
|
|
@ -81,12 +81,12 @@ class ServerRequestTest extends TestCase
|
||||||
public function methodProvider()
|
public function methodProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["GET", "GET"],
|
['GET', 'GET'],
|
||||||
["POST", "POST"],
|
['POST', 'POST'],
|
||||||
["DELETE", "DELETE"],
|
['DELETE', 'DELETE'],
|
||||||
["PUT", "PUT"],
|
['PUT', 'PUT'],
|
||||||
["OPTIONS", "OPTIONS"],
|
['OPTIONS', 'OPTIONS'],
|
||||||
["GET", null]
|
['GET', null]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,8 +97,8 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsRequestTargetFromRequest($expectedRequestTarget, $serverRequestUri)
|
public function testGetServerRequestReadsRequestTargetFromRequest($expectedRequestTarget, $serverRequestUri)
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"REQUEST_URI" => $serverRequestUri
|
'REQUEST_URI' => $serverRequestUri
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertEquals($expectedRequestTarget, $request->getRequestTarget());
|
$this->assertEquals($expectedRequestTarget, $request->getRequestTarget());
|
||||||
|
|
@ -107,10 +107,10 @@ class ServerRequestTest extends TestCase
|
||||||
public function requestTargetProvider()
|
public function requestTargetProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["/", "/"],
|
['/', '/'],
|
||||||
["/hello", "/hello"],
|
['/hello', '/hello'],
|
||||||
["/my/path.txt", "/my/path.txt"],
|
['/my/path.txt', '/my/path.txt'],
|
||||||
["/", null]
|
['/', null]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsHeaders($request)
|
public function testGetServerRequestReadsHeaders($request)
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request */
|
/** @var ServerRequest $request */
|
||||||
$this->assertEquals(["application/json"], $request->getHeader("Accept"));
|
$this->assertEquals(['application/json'], $request->getHeader('Accept'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,12 +127,12 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsContentHeaders()
|
public function testGetServerRequestReadsContentHeaders()
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"CONTENT_LENGTH" => "1024",
|
'CONTENT_LENGTH' => '1024',
|
||||||
"CONTENT_TYPE" => "application/json"
|
'CONTENT_TYPE' => 'application/json'
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertEquals("1024", $request->getHeaderLine("Content-length"));
|
$this->assertEquals('1024', $request->getHeaderLine('Content-length'));
|
||||||
$this->assertEquals("application/json", $request->getHeaderLine("Content-type"));
|
$this->assertEquals('application/json', $request->getHeaderLine('Content-type'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -141,22 +141,22 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestDoesNotReadEmptyContentHeaders()
|
public function testGetServerRequestDoesNotReadEmptyContentHeaders()
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"CONTENT_LENGTH" => "",
|
'CONTENT_LENGTH' => '',
|
||||||
"CONTENT_TYPE" => " "
|
'CONTENT_TYPE' => ' '
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertFalse($request->hasHeader("Content-length"));
|
$this->assertFalse($request->hasHeader('Content-length'));
|
||||||
$this->assertFalse($request->hasHeader("Content-type"));
|
$this->assertFalse($request->hasHeader('Content-type'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetServerRequestReadsBody()
|
public function testGetServerRequestReadsBody()
|
||||||
{
|
{
|
||||||
$body = new NullStream();
|
$body = new NullStream();
|
||||||
$request = $this->getMockBuilder('WellRESTed\Message\ServerRequest')
|
$request = $this->getMockBuilder('WellRESTed\Message\ServerRequest')
|
||||||
->setMethods(["getStreamForBody"])
|
->setMethods(['getStreamForBody'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$request->expects($this->any())
|
$request->expects($this->any())
|
||||||
->method("getStreamForBody")
|
->method('getStreamForBody')
|
||||||
->will($this->returnValue($body));
|
->will($this->returnValue($body));
|
||||||
|
|
||||||
$called = false;
|
$called = false;
|
||||||
|
|
@ -185,30 +185,30 @@ class ServerRequestTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
new Uri("http://localhost/path"),
|
new Uri('http://localhost/path'),
|
||||||
[
|
[
|
||||||
"HTTPS" => "off",
|
'HTTPS' => 'off',
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"REQUEST_URI" => "/path",
|
'REQUEST_URI' => '/path',
|
||||||
"QUERY_STRING" => ""
|
'QUERY_STRING' => ''
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
new Uri("https://foo.com/path/to/stuff?cat=molly"),
|
new Uri('https://foo.com/path/to/stuff?cat=molly'),
|
||||||
[
|
[
|
||||||
"HTTPS" => "1",
|
'HTTPS' => '1',
|
||||||
"HTTP_HOST" => "foo.com",
|
'HTTP_HOST' => 'foo.com',
|
||||||
"REQUEST_URI" => "/path/to/stuff?cat=molly",
|
'REQUEST_URI' => '/path/to/stuff?cat=molly',
|
||||||
"QUERY_STRING" => "cat=molly"
|
'QUERY_STRING' => 'cat=molly'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
new Uri("http://foo.com:8080/path/to/stuff?cat=molly"),
|
new Uri('http://foo.com:8080/path/to/stuff?cat=molly'),
|
||||||
[
|
[
|
||||||
"HTTP" => "1",
|
'HTTP' => '1',
|
||||||
"HTTP_HOST" => "foo.com:8080",
|
'HTTP_HOST' => 'foo.com:8080',
|
||||||
"REQUEST_URI" => "/path/to/stuff?cat=molly",
|
'REQUEST_URI' => '/path/to/stuff?cat=molly',
|
||||||
"QUERY_STRING" => "cat=molly"
|
'QUERY_STRING' => 'cat=molly'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
@ -221,21 +221,21 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsServerParams($request)
|
public function testGetServerRequestReadsServerParams($request)
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request */
|
/** @var ServerRequest $request */
|
||||||
$this->assertEquals("localhost", $request->getServerParams()["HTTP_HOST"]);
|
$this->assertEquals('localhost', $request->getServerParams()['HTTP_HOST']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @depends testGetServerRequestReadsFromRequest */
|
/** @depends testGetServerRequestReadsFromRequest */
|
||||||
public function testGetServerRequestReadsCookieParams($request)
|
public function testGetServerRequestReadsCookieParams($request)
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request */
|
/** @var ServerRequest $request */
|
||||||
$this->assertEquals("Molly", $request->getCookieParams()["cat"]);
|
$this->assertEquals('Molly', $request->getCookieParams()['cat']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @depends testGetServerRequestReadsFromRequest */
|
/** @depends testGetServerRequestReadsFromRequest */
|
||||||
public function testGetServerRequestReadsQueryParams($request)
|
public function testGetServerRequestReadsQueryParams($request)
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request */
|
/** @var ServerRequest $request */
|
||||||
$this->assertEquals("Claude", $request->getQueryParams()["guinea_pig"]);
|
$this->assertEquals('Claude', $request->getQueryParams()['guinea_pig']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -245,77 +245,77 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestReadsUploadedFiles($file, $path)
|
public function testGetServerRequestReadsUploadedFiles($file, $path)
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"HTTP_ACCEPT" => "application/json",
|
'HTTP_ACCEPT' => 'application/json',
|
||||||
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded"
|
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
|
||||||
];
|
];
|
||||||
$_FILES = [
|
$_FILES = [
|
||||||
"single" => [
|
'single' => [
|
||||||
"name" => "single.txt",
|
'name' => 'single.txt',
|
||||||
"type" => "text/plain",
|
'type' => 'text/plain',
|
||||||
"tmp_name" => "/tmp/php9hNlHe",
|
'tmp_name' => '/tmp/php9hNlHe',
|
||||||
"error" => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
"size" => 524
|
'size' => 524
|
||||||
],
|
],
|
||||||
"nested" => [
|
'nested' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"name" => "nested.json",
|
'name' => 'nested.json',
|
||||||
"type" => "application/json",
|
'type' => 'application/json',
|
||||||
"tmp_name" => "/tmp/phpadhjk",
|
'tmp_name' => '/tmp/phpadhjk',
|
||||||
"error" => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
"size" => 1024
|
'size' => 1024
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"nestedList" => [
|
'nestedList' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"name" => [
|
'name' => [
|
||||||
0 => "nestedList0.jpg",
|
0 => 'nestedList0.jpg',
|
||||||
1 => "nestedList1.jpg",
|
1 => 'nestedList1.jpg',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"type" => [
|
'type' => [
|
||||||
0 => "image/jpeg",
|
0 => 'image/jpeg',
|
||||||
1 => "image/jpeg",
|
1 => 'image/jpeg',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"tmp_name" => [
|
'tmp_name' => [
|
||||||
0 => "/tmp/phpjpg0",
|
0 => '/tmp/phpjpg0',
|
||||||
1 => "/tmp/phpjpg1",
|
1 => '/tmp/phpjpg1',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"error" => [
|
'error' => [
|
||||||
0 => UPLOAD_ERR_OK,
|
0 => UPLOAD_ERR_OK,
|
||||||
1 => UPLOAD_ERR_OK,
|
1 => UPLOAD_ERR_OK,
|
||||||
2 => UPLOAD_ERR_NO_FILE
|
2 => UPLOAD_ERR_NO_FILE
|
||||||
],
|
],
|
||||||
"size" => [
|
'size' => [
|
||||||
0 => 256,
|
0 => 256,
|
||||||
1 => 4096,
|
1 => 4096,
|
||||||
2 => 0
|
2 => 0
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"nestedDictionary" => [
|
'nestedDictionary' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"name" => [
|
'name' => [
|
||||||
"file0" => "nestedDictionary0.jpg",
|
'file0' => 'nestedDictionary0.jpg',
|
||||||
"file1" => "nestedDictionary1.jpg"
|
'file1' => 'nestedDictionary1.jpg'
|
||||||
],
|
],
|
||||||
"type" => [
|
'type' => [
|
||||||
"file0" => "image/png",
|
'file0' => 'image/png',
|
||||||
"file1" => "image/png"
|
'file1' => 'image/png'
|
||||||
],
|
],
|
||||||
"tmp_name" => [
|
'tmp_name' => [
|
||||||
"file0" => "/tmp/phppng0",
|
'file0' => '/tmp/phppng0',
|
||||||
"file1" => "/tmp/phppng1"
|
'file1' => '/tmp/phppng1'
|
||||||
],
|
],
|
||||||
"error" => [
|
'error' => [
|
||||||
"file0" => UPLOAD_ERR_OK,
|
'file0' => UPLOAD_ERR_OK,
|
||||||
"file1" => UPLOAD_ERR_OK
|
'file1' => UPLOAD_ERR_OK
|
||||||
],
|
],
|
||||||
"size" => [
|
'size' => [
|
||||||
"file0" => 256,
|
'file0' => 256,
|
||||||
"file1" => 4096
|
'file1' => 4096
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
@ -331,13 +331,13 @@ class ServerRequestTest extends TestCase
|
||||||
public function uploadedFileProvider()
|
public function uploadedFileProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[new UploadedFile("single.txt", "text/plain", 524, "/tmp/php9hNlHe", UPLOAD_ERR_OK), ["single"]],
|
[new UploadedFile('single.txt', 'text/plain', 524, '/tmp/php9hNlHe', UPLOAD_ERR_OK), ['single']],
|
||||||
[new UploadedFile("nested.json", "application/json", 1024, "/tmp/phpadhjk", UPLOAD_ERR_OK), ["nested", "level2"]],
|
[new UploadedFile('nested.json', 'application/json', 1024, '/tmp/phpadhjk', UPLOAD_ERR_OK), ['nested', 'level2']],
|
||||||
[new UploadedFile("nestedList0.jpg", "image/jpeg", 256, "/tmp/phpjpg0", UPLOAD_ERR_OK), ["nestedList", "level2", 0]],
|
[new UploadedFile('nestedList0.jpg', 'image/jpeg', 256, '/tmp/phpjpg0', UPLOAD_ERR_OK), ['nestedList', 'level2', 0]],
|
||||||
[new UploadedFile("nestedList1.jpg", "image/jpeg", 4096, "/tmp/phpjpg1", UPLOAD_ERR_OK), ["nestedList", "level2", 1]],
|
[new UploadedFile('nestedList1.jpg', 'image/jpeg', 4096, '/tmp/phpjpg1', UPLOAD_ERR_OK), ['nestedList', 'level2', 1]],
|
||||||
[new UploadedFile("", "", 0, "", UPLOAD_ERR_NO_FILE), ["nestedList", "level2", 2]],
|
[new UploadedFile('', '', 0, '', UPLOAD_ERR_NO_FILE), ['nestedList', 'level2', 2]],
|
||||||
[new UploadedFile("nestedDictionary0.jpg", "image/png", 256, "/tmp/phppng0", UPLOAD_ERR_OK), ["nestedDictionary", "level2", "file0"]],
|
[new UploadedFile('nestedDictionary0.jpg', 'image/png', 256, '/tmp/phppng0', UPLOAD_ERR_OK), ['nestedDictionary', 'level2', 'file0']],
|
||||||
[new UploadedFile("nestedDictionary1.jpg", "image/png", 4096, "/tmp/phppngg1", UPLOAD_ERR_OK), ["nestedDictionary", "level2", "file1"]]
|
[new UploadedFile('nestedDictionary1.jpg', 'image/png', 4096, '/tmp/phppngg1', UPLOAD_ERR_OK), ['nestedDictionary', 'level2', 'file1']]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,23 +348,23 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestParsesFormBody($contentType)
|
public function testGetServerRequestParsesFormBody($contentType)
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"HTTP_CONTENT_TYPE" => $contentType,
|
'HTTP_CONTENT_TYPE' => $contentType,
|
||||||
];
|
];
|
||||||
$_COOKIE = [];
|
$_COOKIE = [];
|
||||||
$_FILES = [];
|
$_FILES = [];
|
||||||
$_POST = [
|
$_POST = [
|
||||||
"dog" => "Bear"
|
'dog' => 'Bear'
|
||||||
];
|
];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
$this->assertEquals("Bear", $request->getParsedBody()["dog"]);
|
$this->assertEquals('Bear', $request->getParsedBody()['dog']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formContentTypeProvider()
|
public function formContentTypeProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["application/x-www-form-urlencoded"],
|
['application/x-www-form-urlencoded'],
|
||||||
["multipart/form-data"]
|
['multipart/form-data']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,7 +372,7 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetServerRequestProvidesAttributesIfPassed($request)
|
public function testGetServerRequestProvidesAttributesIfPassed($request)
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request */
|
/** @var ServerRequest $request */
|
||||||
$this->assertEquals("Claude", $request->getAttribute("guinea_pig"));
|
$this->assertEquals('Claude', $request->getAttribute('guinea_pig'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -398,9 +398,9 @@ class ServerRequestTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request1 */
|
/** @var ServerRequest $request1 */
|
||||||
$request2 = $request1->withCookieParams([
|
$request2 = $request1->withCookieParams([
|
||||||
"cat" => "Oscar"
|
'cat' => 'Oscar'
|
||||||
]);
|
]);
|
||||||
$this->assertNotEquals($request1->getCookieParams()["cat"], $request2->getCookieParams()["cat"]);
|
$this->assertNotEquals($request1->getCookieParams()['cat'], $request2->getCookieParams()['cat']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -417,9 +417,9 @@ class ServerRequestTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var ServerRequest $request1 */
|
/** @var ServerRequest $request1 */
|
||||||
$request2 = $request1->withQueryParams([
|
$request2 = $request1->withQueryParams([
|
||||||
"guinea_pig" => "Clyde"
|
'guinea_pig' => 'Clyde'
|
||||||
]);
|
]);
|
||||||
$this->assertNotEquals($request1->getQueryParams()["guinea_pig"], $request2->getQueryParams()["guinea_pig"]);
|
$this->assertNotEquals($request1->getQueryParams()['guinea_pig'], $request2->getQueryParams()['guinea_pig']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -435,9 +435,9 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetUploadedFilesReturnsEmptyArrayWhenNoFilesAreUploaded()
|
public function testGetUploadedFilesReturnsEmptyArrayWhenNoFilesAreUploaded()
|
||||||
{
|
{
|
||||||
$_SERVER = [
|
$_SERVER = [
|
||||||
"HTTP_HOST" => "localhost",
|
'HTTP_HOST' => 'localhost',
|
||||||
"HTTP_ACCEPT" => "application/json",
|
'HTTP_ACCEPT' => 'application/json',
|
||||||
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded"
|
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
|
||||||
];
|
];
|
||||||
$_FILES = [];
|
$_FILES = [];
|
||||||
$request = ServerRequest::getServerRequest();
|
$request = ServerRequest::getServerRequest();
|
||||||
|
|
@ -447,7 +447,7 @@ class ServerRequestTest extends TestCase
|
||||||
public function testWithUploadedFilesCreatesNewInstance()
|
public function testWithUploadedFilesCreatesNewInstance()
|
||||||
{
|
{
|
||||||
$uploadedFiles = [
|
$uploadedFiles = [
|
||||||
"file" => new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)
|
'file' => new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)
|
||||||
];
|
];
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request1 = $request->withUploadedFiles([]);
|
$request1 = $request->withUploadedFiles([]);
|
||||||
|
|
@ -467,20 +467,20 @@ class ServerRequestTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[[]],
|
[[]],
|
||||||
[["files" => new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)]],
|
[['files' => new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)]],
|
||||||
[["nested" => [
|
[['nested' => [
|
||||||
"level2" => new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)
|
'level2' => new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)
|
||||||
]]],
|
]]],
|
||||||
[["nestedList" => [
|
[['nestedList' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
new UploadedFile("file1.html", "text/html", 524, "/tmp/php9hNlHe", 0),
|
new UploadedFile('file1.html', 'text/html', 524, '/tmp/php9hNlHe', 0),
|
||||||
new UploadedFile("file2.html", "text/html", 524, "/tmp/php9hNshj", 0)
|
new UploadedFile('file2.html', 'text/html', 524, '/tmp/php9hNshj', 0)
|
||||||
]
|
]
|
||||||
]]],
|
]]],
|
||||||
[["nestedDictionary" => [
|
[['nestedDictionary' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"file1" => new UploadedFile("file1.html", "text/html", 524, "/tmp/php9hNlHe", 0),
|
'file1' => new UploadedFile('file1.html', 'text/html', 524, '/tmp/php9hNlHe', 0),
|
||||||
"file2" => new UploadedFile("file2.html", "text/html", 524, "/tmp/php9hNshj", 0)
|
'file2' => new UploadedFile('file2.html', 'text/html', 524, '/tmp/php9hNshj', 0)
|
||||||
]
|
]
|
||||||
]]]
|
]]]
|
||||||
];
|
];
|
||||||
|
|
@ -500,53 +500,53 @@ class ServerRequestTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// All keys must be strings
|
// All keys must be strings
|
||||||
[[new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)]],
|
[[new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)]],
|
||||||
[
|
[
|
||||||
[new UploadedFile("index1.html", "text/html", 524, "/tmp/php9hNlHe", 0)],
|
[new UploadedFile('index1.html', 'text/html', 524, '/tmp/php9hNlHe', 0)],
|
||||||
[new UploadedFile("index2.html", "text/html", 524, "/tmp/php9hNlHe", 0)]
|
[new UploadedFile('index2.html', 'text/html', 524, '/tmp/php9hNlHe', 0)]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"single" => [
|
'single' => [
|
||||||
"name" => "single.txt",
|
'name' => 'single.txt',
|
||||||
"type" => "text/plain",
|
'type' => 'text/plain',
|
||||||
"tmp_name" => "/tmp/php9hNlHe",
|
'tmp_name' => '/tmp/php9hNlHe',
|
||||||
"error" => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
"size" => 524
|
'size' => 524
|
||||||
],
|
],
|
||||||
"nested" => [
|
'nested' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"name" => "nested.json",
|
'name' => 'nested.json',
|
||||||
"type" => "application/json",
|
'type' => 'application/json',
|
||||||
"tmp_name" => "/tmp/phpadhjk",
|
'tmp_name' => '/tmp/phpadhjk',
|
||||||
"error" => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
"size" => 1024
|
'size' => 1024
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"nestedList" => [
|
'nestedList' => [
|
||||||
"level2" => [
|
'level2' => [
|
||||||
"name" => [
|
'name' => [
|
||||||
0 => "nestedList0.jpg",
|
0 => 'nestedList0.jpg',
|
||||||
1 => "nestedList1.jpg",
|
1 => 'nestedList1.jpg',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"type" => [
|
'type' => [
|
||||||
0 => "image/jpeg",
|
0 => 'image/jpeg',
|
||||||
1 => "image/jpeg",
|
1 => 'image/jpeg',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"tmp_name" => [
|
'tmp_name' => [
|
||||||
0 => "/tmp/phpjpg0",
|
0 => '/tmp/phpjpg0',
|
||||||
1 => "/tmp/phpjpg1",
|
1 => '/tmp/phpjpg1',
|
||||||
2 => ""
|
2 => ''
|
||||||
],
|
],
|
||||||
"error" => [
|
'error' => [
|
||||||
0 => UPLOAD_ERR_OK,
|
0 => UPLOAD_ERR_OK,
|
||||||
1 => UPLOAD_ERR_OK,
|
1 => UPLOAD_ERR_OK,
|
||||||
2 => UPLOAD_ERR_NO_FILE
|
2 => UPLOAD_ERR_NO_FILE
|
||||||
],
|
],
|
||||||
"size" => [
|
'size' => [
|
||||||
0 => 256,
|
0 => 256,
|
||||||
1 => 4096,
|
1 => 4096,
|
||||||
2 => 0
|
2 => 0
|
||||||
|
|
@ -573,7 +573,7 @@ class ServerRequestTest extends TestCase
|
||||||
$body1 = $request1->getParsedBody();
|
$body1 = $request1->getParsedBody();
|
||||||
|
|
||||||
$request2 = $request1->withParsedBody([
|
$request2 = $request1->withParsedBody([
|
||||||
"guinea_pig" => "Clyde"
|
'guinea_pig' => 'Clyde'
|
||||||
]);
|
]);
|
||||||
$body2 = $request2->getParsedBody();
|
$body2 = $request2->getParsedBody();
|
||||||
|
|
||||||
|
|
@ -601,12 +601,12 @@ class ServerRequestTest extends TestCase
|
||||||
public function testCloneMakesDeepCopiesOfParsedBody()
|
public function testCloneMakesDeepCopiesOfParsedBody()
|
||||||
{
|
{
|
||||||
$body = (object) [
|
$body = (object) [
|
||||||
"cat" => "Dog"
|
'cat' => 'Dog'
|
||||||
];
|
];
|
||||||
|
|
||||||
$request1 = new ServerRequest();
|
$request1 = new ServerRequest();
|
||||||
$request1 = $request1->withParsedBody($body);
|
$request1 = $request1->withParsedBody($body);
|
||||||
$request2 = $request1->withHeader("X-extra", "hello world");
|
$request2 = $request1->withHeader('X-extra', 'hello world');
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$request1->getParsedBody() == $request2->getParsedBody()
|
$request1->getParsedBody() == $request2->getParsedBody()
|
||||||
|
|
@ -626,11 +626,11 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetAttributesReturnsAllAttributes()
|
public function testGetAttributesReturnsAllAttributes()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$request = $request->withAttribute("dog", "Bear");
|
$request = $request->withAttribute('dog', 'Bear');
|
||||||
$expected = [
|
$expected = [
|
||||||
"cat" => "Molly",
|
'cat' => 'Molly',
|
||||||
"dog" => "Bear"
|
'dog' => 'Bear'
|
||||||
];
|
];
|
||||||
$this->assertEquals($expected, $request->getAttributes());
|
$this->assertEquals($expected, $request->getAttributes());
|
||||||
}
|
}
|
||||||
|
|
@ -638,24 +638,24 @@ class ServerRequestTest extends TestCase
|
||||||
public function testGetAttributeReturnsDefaultIfNotSet()
|
public function testGetAttributeReturnsDefaultIfNotSet()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$this->assertEquals("Oscar", $request->getAttribute("cat", "Oscar"));
|
$this->assertEquals('Oscar', $request->getAttribute('cat', 'Oscar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithAttributeCreatesNewInstance()
|
public function testWithAttributeCreatesNewInstance()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$this->assertEquals("Molly", $request->getAttribute("cat"));
|
$this->assertEquals('Molly', $request->getAttribute('cat'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithAttributePreserversOtherAttributes()
|
public function testWithAttributePreserversOtherAttributes()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$request = $request->withAttribute("dog", "Bear");
|
$request = $request->withAttribute('dog', 'Bear');
|
||||||
$expected = [
|
$expected = [
|
||||||
"cat" => "Molly",
|
'cat' => 'Molly',
|
||||||
"dog" => "Bear"
|
'dog' => 'Bear'
|
||||||
];
|
];
|
||||||
$this->assertEquals($expected, $request->getAttributes());
|
$this->assertEquals($expected, $request->getAttributes());
|
||||||
}
|
}
|
||||||
|
|
@ -663,24 +663,24 @@ class ServerRequestTest extends TestCase
|
||||||
public function testWithoutAttributeCreatesNewInstance()
|
public function testWithoutAttributeCreatesNewInstance()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$this->assertNotEquals($request, $request->withoutAttribute("cat"));
|
$this->assertNotEquals($request, $request->withoutAttribute('cat'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithoutAttributeRemovesAttribute()
|
public function testWithoutAttributeRemovesAttribute()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$request = $request->withoutAttribute("cat");
|
$request = $request->withoutAttribute('cat');
|
||||||
$this->assertEquals("Oscar", $request->getAttribute("cat", "Oscar"));
|
$this->assertEquals('Oscar', $request->getAttribute('cat', 'Oscar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithoutAttributePreservesOtherAttributes()
|
public function testWithoutAttributePreservesOtherAttributes()
|
||||||
{
|
{
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withAttribute("cat", "Molly");
|
$request = $request->withAttribute('cat', 'Molly');
|
||||||
$request = $request->withAttribute("dog", "Bear");
|
$request = $request->withAttribute('dog', 'Bear');
|
||||||
$request = $request->withoutAttribute("cat");
|
$request = $request->withoutAttribute('cat');
|
||||||
$this->assertEquals("Bear", $request->getAttribute("dog"));
|
$this->assertEquals('Bear', $request->getAttribute('dog'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ class StreamTest extends TestCase
|
||||||
{
|
{
|
||||||
private $resource;
|
private $resource;
|
||||||
private $resourceDevNull;
|
private $resourceDevNull;
|
||||||
private $content = "Hello, world!";
|
private $content = 'Hello, world!';
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->resource = fopen("php://memory", "w+");
|
$this->resource = fopen('php://memory', 'w+');
|
||||||
$this->resourceDevNull = fopen("/dev/null", "r");
|
$this->resourceDevNull = fopen('/dev/null', 'r');
|
||||||
fwrite($this->resource, $this->content);
|
fwrite($this->resource, $this->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ class StreamTest extends TestCase
|
||||||
|
|
||||||
public function testCreatesInstanceWithString()
|
public function testCreatesInstanceWithString()
|
||||||
{
|
{
|
||||||
$stream = new Stream("Hello, world!");
|
$stream = new Stream('Hello, world!');
|
||||||
$this->assertNotNull($stream);
|
$this->assertNotNull($stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ class StreamTest extends TestCase
|
||||||
{
|
{
|
||||||
$stream = new Stream($this->resource);
|
$stream = new Stream($this->resource);
|
||||||
$metadata = stream_get_meta_data($this->resource);
|
$metadata = stream_get_meta_data($this->resource);
|
||||||
$seekable = $metadata["seekable"] == 1;
|
$seekable = $metadata['seekable'] == 1;
|
||||||
$this->assertEquals($seekable, $stream->isSeekable());
|
$this->assertEquals($seekable, $stream->isSeekable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,17 +167,17 @@ class StreamTest extends TestCase
|
||||||
public function testThrowsExceptionOnErrorWriting()
|
public function testThrowsExceptionOnErrorWriting()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$filename = tempnam(sys_get_temp_dir(), "php");
|
$filename = tempnam(sys_get_temp_dir(), 'php');
|
||||||
$handle = fopen($filename, "r");
|
$handle = fopen($filename, 'r');
|
||||||
$stream = new Stream($handle);
|
$stream = new Stream($handle);
|
||||||
$stream->write("Hello, world!");
|
$stream->write('Hello, world!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsExceptionOnErrorReading()
|
public function testThrowsExceptionOnErrorReading()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$filename = tempnam(sys_get_temp_dir(), "php");
|
$filename = tempnam(sys_get_temp_dir(), 'php');
|
||||||
$handle = fopen($filename, "w");
|
$handle = fopen($filename, 'w');
|
||||||
$stream = new Stream($handle);
|
$stream = new Stream($handle);
|
||||||
$stream->read(10);
|
$stream->read(10);
|
||||||
}
|
}
|
||||||
|
|
@ -187,14 +187,14 @@ class StreamTest extends TestCase
|
||||||
$stream = new Stream($this->resource);
|
$stream = new Stream($this->resource);
|
||||||
$stream->seek(7);
|
$stream->seek(7);
|
||||||
$string = $stream->read(5);
|
$string = $stream->read(5);
|
||||||
$this->assertEquals("world", $string);
|
$this->assertEquals('world', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsExceptionOnErrorReadingToEnd()
|
public function testThrowsExceptionOnErrorReadingToEnd()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$filename = tempnam(sys_get_temp_dir(), "php");
|
$filename = tempnam(sys_get_temp_dir(), 'php');
|
||||||
$handle = fopen($filename, "w");
|
$handle = fopen($filename, 'w');
|
||||||
$stream = new Stream($handle);
|
$stream = new Stream($handle);
|
||||||
$stream->getContents();
|
$stream->getContents();
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +204,7 @@ class StreamTest extends TestCase
|
||||||
$stream = new Stream($this->resource);
|
$stream = new Stream($this->resource);
|
||||||
$stream->seek(7);
|
$stream->seek(7);
|
||||||
$string = $stream->getContents();
|
$string = $stream->getContents();
|
||||||
$this->assertEquals("world!", $string);
|
$this->assertEquals('world!', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnsMetadataArray()
|
public function testReturnsMetadataArray()
|
||||||
|
|
@ -217,7 +217,7 @@ class StreamTest extends TestCase
|
||||||
{
|
{
|
||||||
$stream = new Stream($this->resource);
|
$stream = new Stream($this->resource);
|
||||||
$metadata = stream_get_meta_data($this->resource);
|
$metadata = stream_get_meta_data($this->resource);
|
||||||
$this->assertEquals($metadata["mode"], $stream->getMetadata("mode"));
|
$this->assertEquals($metadata['mode'], $stream->getMetadata('mode'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -228,8 +228,8 @@ class StreamTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testReturnsIsReadableForReadableStreams($mode, $readable, $writable)
|
public function testReturnsIsReadableForReadableStreams($mode, $readable, $writable)
|
||||||
{
|
{
|
||||||
$tmp = tempnam(sys_get_temp_dir(), "php");
|
$tmp = tempnam(sys_get_temp_dir(), 'php');
|
||||||
if ($mode[0] === "x") {
|
if ($mode[0] === 'x') {
|
||||||
unlink($tmp);
|
unlink($tmp);
|
||||||
}
|
}
|
||||||
$resource = fopen($tmp, $mode);
|
$resource = fopen($tmp, $mode);
|
||||||
|
|
@ -245,8 +245,8 @@ class StreamTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writable)
|
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writable)
|
||||||
{
|
{
|
||||||
$tmp = tempnam(sys_get_temp_dir(), "php");
|
$tmp = tempnam(sys_get_temp_dir(), 'php');
|
||||||
if ($mode[0] === "x") {
|
if ($mode[0] === 'x') {
|
||||||
unlink($tmp);
|
unlink($tmp);
|
||||||
}
|
}
|
||||||
$resource = fopen($tmp, $mode);
|
$resource = fopen($tmp, $mode);
|
||||||
|
|
@ -257,16 +257,16 @@ class StreamTest extends TestCase
|
||||||
public function modeProvider()
|
public function modeProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["r", true, false],
|
['r', true, false],
|
||||||
["r+", true, true],
|
['r+', true, true],
|
||||||
["w", false, true],
|
['w', false, true],
|
||||||
["w+", true, true],
|
['w+', true, true],
|
||||||
["a", false, true],
|
['a', false, true],
|
||||||
["a+", true, true],
|
['a+', true, true],
|
||||||
["x", false, true],
|
['x', false, true],
|
||||||
["x+", true, true],
|
['x+', true, true],
|
||||||
["c", false, true],
|
['c', false, true],
|
||||||
["c+", true, true]
|
['c+', true, true]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use WellRESTed\Message\UploadedFileState;
|
||||||
use WellRESTed\Test\TestCase;
|
use WellRESTed\Test\TestCase;
|
||||||
|
|
||||||
// Hides several php core functions for testing.
|
// Hides several php core functions for testing.
|
||||||
require_once __DIR__ . "/../../../src/UploadedFileState.php";
|
require_once __DIR__ . '/../../../src/UploadedFileState.php';
|
||||||
|
|
||||||
class UploadedFileTest extends TestCase
|
class UploadedFileTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
@ -19,9 +19,9 @@ class UploadedFileTest extends TestCase
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
UploadedFileState::$php_sapi_name = "cli";
|
UploadedFileState::$php_sapi_name = 'cli';
|
||||||
$this->tmpName = tempnam(sys_get_temp_dir(), "tst");
|
$this->tmpName = tempnam(sys_get_temp_dir(), 'tst');
|
||||||
$this->movePath = tempnam(sys_get_temp_dir(), "tst");
|
$this->movePath = tempnam(sys_get_temp_dir(), 'tst');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void
|
public function tearDown(): void
|
||||||
|
|
@ -40,22 +40,22 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testGetStreamReturnsStreamInterface()
|
public function testGetStreamReturnsStreamInterface()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, 0);
|
$file = new UploadedFile('', '', 0, $this->tmpName, 0);
|
||||||
$this->assertInstanceOf(StreamInterface::class, $file->getStream());
|
$this->assertInstanceOf(StreamInterface::class, $file->getStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStreamReturnsStreamWrappingUploadedFile()
|
public function testGetStreamReturnsStreamWrappingUploadedFile()
|
||||||
{
|
{
|
||||||
$content = "Hello, World!";
|
$content = 'Hello, World!';
|
||||||
file_put_contents($this->tmpName, $content);
|
file_put_contents($this->tmpName, $content);
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, "");
|
$file = new UploadedFile('', '', 0, $this->tmpName, '');
|
||||||
$stream = $file->getStream();
|
$stream = $file->getStream();
|
||||||
$this->assertEquals($content, (string) $stream);
|
$this->assertEquals($content, (string) $stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStreamThrowsRuntimeExceptionForNoFile()
|
public function testGetStreamThrowsRuntimeExceptionForNoFile()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("", "", 0, "", 0);
|
$file = new UploadedFile('', '', 0, '', 0);
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$file->getStream();
|
$file->getStream();
|
||||||
}
|
}
|
||||||
|
|
@ -63,9 +63,9 @@ class UploadedFileTest extends TestCase
|
||||||
public function testGetStreamThrowsExceptionAfterMoveTo()
|
public function testGetStreamThrowsExceptionAfterMoveTo()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
$content = "Hello, World!";
|
$content = 'Hello, World!';
|
||||||
file_put_contents($this->tmpName, $content);
|
file_put_contents($this->tmpName, $content);
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, "");
|
$file = new UploadedFile('', '', 0, $this->tmpName, '');
|
||||||
$file->moveTo($this->movePath);
|
$file->moveTo($this->movePath);
|
||||||
$file->getStream();
|
$file->getStream();
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +73,9 @@ class UploadedFileTest extends TestCase
|
||||||
public function testGetStreamThrowsExceptionForNonUploadedFile()
|
public function testGetStreamThrowsExceptionForNonUploadedFile()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
UploadedFileState::$php_sapi_name = "apache";
|
UploadedFileState::$php_sapi_name = 'apache';
|
||||||
UploadedFileState::$is_uploaded_file = false;
|
UploadedFileState::$is_uploaded_file = false;
|
||||||
$file = new UploadedFile("", "", 0, "", 0);
|
$file = new UploadedFile('', '', 0, '', 0);
|
||||||
$file->getStream();
|
$file->getStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,13 +84,13 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testMoveToSapiRelocatesUploadedFileToDestinationIfExists()
|
public function testMoveToSapiRelocatesUploadedFileToDestinationIfExists()
|
||||||
{
|
{
|
||||||
UploadedFileState::$php_sapi_name = "fpm-fcgi";
|
UploadedFileState::$php_sapi_name = 'fpm-fcgi';
|
||||||
|
|
||||||
$content = "Hello, World!";
|
$content = 'Hello, World!';
|
||||||
file_put_contents($this->tmpName, $content);
|
file_put_contents($this->tmpName, $content);
|
||||||
$originalMd5 = md5_file($this->tmpName);
|
$originalMd5 = md5_file($this->tmpName);
|
||||||
|
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, "");
|
$file = new UploadedFile('', '', 0, $this->tmpName, '');
|
||||||
$file->moveTo($this->movePath);
|
$file->moveTo($this->movePath);
|
||||||
|
|
||||||
$this->assertEquals($originalMd5, md5_file($this->movePath));
|
$this->assertEquals($originalMd5, md5_file($this->movePath));
|
||||||
|
|
@ -98,11 +98,11 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testMoveToNonSapiRelocatesUploadedFileToDestinationIfExists()
|
public function testMoveToNonSapiRelocatesUploadedFileToDestinationIfExists()
|
||||||
{
|
{
|
||||||
$content = "Hello, World!";
|
$content = 'Hello, World!';
|
||||||
file_put_contents($this->tmpName, $content);
|
file_put_contents($this->tmpName, $content);
|
||||||
$originalMd5 = md5_file($this->tmpName);
|
$originalMd5 = md5_file($this->tmpName);
|
||||||
|
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, "");
|
$file = new UploadedFile('', '', 0, $this->tmpName, '');
|
||||||
$file->moveTo($this->movePath);
|
$file->moveTo($this->movePath);
|
||||||
|
|
||||||
$this->assertEquals($originalMd5, md5_file($this->movePath));
|
$this->assertEquals($originalMd5, md5_file($this->movePath));
|
||||||
|
|
@ -112,10 +112,10 @@ class UploadedFileTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
$content = "Hello, World!";
|
$content = 'Hello, World!';
|
||||||
file_put_contents($this->tmpName, $content);
|
file_put_contents($this->tmpName, $content);
|
||||||
|
|
||||||
$file = new UploadedFile("", "", 0, $this->tmpName, "");
|
$file = new UploadedFile('', '', 0, $this->tmpName, '');
|
||||||
$file->moveTo($this->movePath);
|
$file->moveTo($this->movePath);
|
||||||
$file->moveTo($this->movePath);
|
$file->moveTo($this->movePath);
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +125,7 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testGetSizeReturnsSize()
|
public function testGetSizeReturnsSize()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("", "", 1024, "", 0);
|
$file = new UploadedFile('', '', 1024, '', 0);
|
||||||
$this->assertEquals(1024, $file->getSize());
|
$this->assertEquals(1024, $file->getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testGetErrorReturnsError()
|
public function testGetErrorReturnsError()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("", "", 1024, "", UPLOAD_ERR_INI_SIZE);
|
$file = new UploadedFile('', '', 1024, '', UPLOAD_ERR_INI_SIZE);
|
||||||
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
|
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,8 +143,8 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testGetClientFilenameReturnsClientFilename()
|
public function testGetClientFilenameReturnsClientFilename()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("clientFilename", "", 0, "", 0);
|
$file = new UploadedFile('clientFilename', '', 0, '', 0);
|
||||||
$this->assertEquals("clientFilename", $file->getClientFilename());
|
$this->assertEquals('clientFilename', $file->getClientFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -152,7 +152,7 @@ class UploadedFileTest extends TestCase
|
||||||
|
|
||||||
public function testGetClientMediaTypeReturnsClientMediaType()
|
public function testGetClientMediaTypeReturnsClientMediaType()
|
||||||
{
|
{
|
||||||
$file = new UploadedFile("", "clientMediaType", 0, "", 0);
|
$file = new UploadedFile('', 'clientMediaType', 0, '', 0);
|
||||||
$this->assertEquals("clientMediaType", $file->getClientMediaType());
|
$this->assertEquals('clientMediaType', $file->getClientMediaType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultSchemeIsEmpty()
|
public function testDefaultSchemeIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getScheme());
|
$this->assertSame('', $uri->getScheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider schemeProvider */
|
/** @dataProvider schemeProvider */
|
||||||
|
|
@ -28,12 +28,12 @@ class UriTest extends TestCase
|
||||||
public function schemeProvider()
|
public function schemeProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["http", "http"],
|
['http', 'http'],
|
||||||
["https", "https"],
|
['https', 'https'],
|
||||||
["http", "HTTP"],
|
['http', 'HTTP'],
|
||||||
["https", "HTTPS"],
|
['https', 'HTTPS'],
|
||||||
["", null],
|
['', null],
|
||||||
["", ""]
|
['', '']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$uri->withScheme("gopher");
|
$uri->withScheme('gopher');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -50,7 +50,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultAuthorityIsEmpty()
|
public function testDefaultAuthorityIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getAuthority());
|
$this->assertSame('', $uri->getAuthority());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRespectsMyAuthoritah()
|
public function testRespectsMyAuthoritah()
|
||||||
|
|
@ -63,25 +63,25 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
|
|
||||||
if (isset($components["scheme"])) {
|
if (isset($components['scheme'])) {
|
||||||
$uri = $uri->withScheme($components["scheme"]);
|
$uri = $uri->withScheme($components['scheme']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["user"])) {
|
if (isset($components['user'])) {
|
||||||
$user = $components["user"];
|
$user = $components['user'];
|
||||||
$password = null;
|
$password = null;
|
||||||
if (isset($components["password"])) {
|
if (isset($components['password'])) {
|
||||||
$password = $components["password"];
|
$password = $components['password'];
|
||||||
}
|
}
|
||||||
$uri = $uri->withUserInfo($user, $password);
|
$uri = $uri->withUserInfo($user, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["host"])) {
|
if (isset($components['host'])) {
|
||||||
$uri = $uri->withHost($components["host"]);
|
$uri = $uri->withHost($components['host']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["port"])) {
|
if (isset($components['port'])) {
|
||||||
$uri = $uri->withPort($components["port"]);
|
$uri = $uri->withPort($components['port']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expected, $uri->getAuthority());
|
$this->assertEquals($expected, $uri->getAuthority());
|
||||||
|
|
@ -91,73 +91,73 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
"localhost",
|
'localhost',
|
||||||
[
|
[
|
||||||
"host" => "localhost"
|
'host' => 'localhost'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"user@localhost",
|
'user@localhost',
|
||||||
[
|
[
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"user" => "user"
|
'user' => 'user'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"user:password@localhost",
|
'user:password@localhost',
|
||||||
[
|
[
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"user" => "user",
|
'user' => 'user',
|
||||||
"password" => "password"
|
'password' => 'password'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"localhost",
|
'localhost',
|
||||||
[
|
[
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"password" => "password"
|
'password' => 'password'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"localhost",
|
'localhost',
|
||||||
[
|
[
|
||||||
"scheme" => "http",
|
'scheme' => 'http',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 80
|
'port' => 80
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"localhost",
|
'localhost',
|
||||||
[
|
[
|
||||||
"scheme" => "https",
|
'scheme' => 'https',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 443
|
'port' => 443
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"localhost:4430",
|
'localhost:4430',
|
||||||
[
|
[
|
||||||
"scheme" => "https",
|
'scheme' => 'https',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 4430
|
'port' => 4430
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"localhost:8080",
|
'localhost:8080',
|
||||||
[
|
[
|
||||||
"scheme" => "http",
|
'scheme' => 'http',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 8080
|
'port' => 8080
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"user:password@localhost:4430",
|
'user:password@localhost:4430',
|
||||||
[
|
[
|
||||||
"scheme" => "https",
|
'scheme' => 'https',
|
||||||
"user" => "user",
|
'user' => 'user',
|
||||||
"password" => "password",
|
'password' => 'password',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 4430
|
'port' => 4430
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
@ -169,7 +169,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultUserInfoIsEmpty()
|
public function testDefaultUserInfoIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getUserInfo());
|
$this->assertSame('', $uri->getUserInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -189,11 +189,11 @@ class UriTest extends TestCase
|
||||||
public function userInfoProvider()
|
public function userInfoProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["user:password", "user", "password"],
|
['user:password', 'user', 'password'],
|
||||||
["user", "user", ""],
|
['user', 'user', ''],
|
||||||
["user", "user", null],
|
['user', 'user', null],
|
||||||
["", "", "password"],
|
['', '', 'password'],
|
||||||
["", "", ""]
|
['', '', '']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultHostIsEmpty()
|
public function testDefaultHostIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getHost());
|
$this->assertSame('', $uri->getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider hostProvider */
|
/** @dataProvider hostProvider */
|
||||||
|
|
@ -217,10 +217,10 @@ class UriTest extends TestCase
|
||||||
public function hostProvider()
|
public function hostProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["", ""],
|
['', ''],
|
||||||
["localhost", "localhost"],
|
['localhost', 'localhost'],
|
||||||
["localhost", "LOCALHOST"],
|
['localhost', 'LOCALHOST'],
|
||||||
["foo.com", "FOO.com"]
|
['foo.com', 'FOO.com']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,13 +255,13 @@ class UriTest extends TestCase
|
||||||
public function testDefaultPortForHttpSchemeIs80()
|
public function testDefaultPortForHttpSchemeIs80()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame(80, $uri->withScheme("http")->getPort());
|
$this->assertSame(80, $uri->withScheme('http')->getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultPortForHttpsSchemeIs443()
|
public function testDefaultPortForHttpsSchemeIs443()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame(443, $uri->withScheme("https")->getPort());
|
$this->assertSame(443, $uri->withScheme('https')->getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider portAndSchemeProvider */
|
/** @dataProvider portAndSchemeProvider */
|
||||||
|
|
@ -275,12 +275,12 @@ class UriTest extends TestCase
|
||||||
public function portAndSchemeProvider()
|
public function portAndSchemeProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[null, "", null],
|
[null, '', null],
|
||||||
[80, "http", null],
|
[80, 'http', null],
|
||||||
[443, "https", null],
|
[443, 'https', null],
|
||||||
[8080, "", 8080],
|
[8080, '', 8080],
|
||||||
[8080, "http", "8080"],
|
[8080, 'http', '8080'],
|
||||||
[8080, "https", 8080.0]
|
[8080, 'https', 8080.0]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -300,7 +300,7 @@ class UriTest extends TestCase
|
||||||
[true],
|
[true],
|
||||||
[-1],
|
[-1],
|
||||||
[65536],
|
[65536],
|
||||||
["dog"]
|
['dog']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,7 +310,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultPathIsEmpty()
|
public function testDefaultPathIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getPath());
|
$this->assertSame('', $uri->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider pathProvider */
|
/** @dataProvider pathProvider */
|
||||||
|
|
@ -333,13 +333,13 @@ class UriTest extends TestCase
|
||||||
public function pathProvider()
|
public function pathProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["", ""],
|
['', ''],
|
||||||
["/", "/"],
|
['/', '/'],
|
||||||
["*", "*"],
|
['*', '*'],
|
||||||
["/my/path", "/my/path"],
|
['/my/path', '/my/path'],
|
||||||
["/encoded%2Fslash", "/encoded%2Fslash"],
|
['/encoded%2Fslash', '/encoded%2Fslash'],
|
||||||
["/percent/%25", "/percent/%"],
|
['/percent/%25', '/percent/%'],
|
||||||
["/%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "/áéíóú"]
|
['/%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', '/áéíóú']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,7 +349,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultQueryIsEmpty()
|
public function testDefaultQueryIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getQuery());
|
$this->assertSame('', $uri->getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider queryProvider */
|
/** @dataProvider queryProvider */
|
||||||
|
|
@ -372,9 +372,9 @@ class UriTest extends TestCase
|
||||||
public function queryProvider()
|
public function queryProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["cat=molly", "cat=molly"],
|
['cat=molly', 'cat=molly'],
|
||||||
["cat=molly&dog=bear", "cat=molly&dog=bear"],
|
['cat=molly&dog=bear', 'cat=molly&dog=bear'],
|
||||||
["accents=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "accents=áéíóú"]
|
['accents=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', 'accents=áéíóú']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -403,7 +403,7 @@ class UriTest extends TestCase
|
||||||
public function testDefaultFragmentIsEmpty()
|
public function testDefaultFragmentIsEmpty()
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
$this->assertSame("", $uri->getFragment());
|
$this->assertSame('', $uri->getFragment());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider fragmentProvider */
|
/** @dataProvider fragmentProvider */
|
||||||
|
|
@ -426,9 +426,9 @@ class UriTest extends TestCase
|
||||||
public function fragmentProvider()
|
public function fragmentProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["", null],
|
['', null],
|
||||||
["molly", "molly"],
|
['molly', 'molly'],
|
||||||
["%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "áéíóú"]
|
['%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', 'áéíóú']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -440,37 +440,37 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
$uri = new Uri();
|
$uri = new Uri();
|
||||||
|
|
||||||
if (isset($components["scheme"])) {
|
if (isset($components['scheme'])) {
|
||||||
$uri = $uri->withScheme($components["scheme"]);
|
$uri = $uri->withScheme($components['scheme']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["user"])) {
|
if (isset($components['user'])) {
|
||||||
$user = $components["user"];
|
$user = $components['user'];
|
||||||
$password = null;
|
$password = null;
|
||||||
if (isset($components["password"])) {
|
if (isset($components['password'])) {
|
||||||
$password = $components["password"];
|
$password = $components['password'];
|
||||||
}
|
}
|
||||||
$uri = $uri->withUserInfo($user, $password);
|
$uri = $uri->withUserInfo($user, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["host"])) {
|
if (isset($components['host'])) {
|
||||||
$uri = $uri->withHost($components["host"]);
|
$uri = $uri->withHost($components['host']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["port"])) {
|
if (isset($components['port'])) {
|
||||||
$uri = $uri->withPort($components["port"]);
|
$uri = $uri->withPort($components['port']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["path"])) {
|
if (isset($components['path'])) {
|
||||||
$uri = $uri->withPath($components["path"]);
|
$uri = $uri->withPath($components['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["query"])) {
|
if (isset($components['query'])) {
|
||||||
$uri = $uri->withQuery($components["query"]);
|
$uri = $uri->withQuery($components['query']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($components["fragment"])) {
|
if (isset($components['fragment'])) {
|
||||||
$uri = $uri->withFragment($components["fragment"]);
|
$uri = $uri->withFragment($components['fragment']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expected, (string) $uri);
|
$this->assertEquals($expected, (string) $uri);
|
||||||
|
|
@ -480,59 +480,59 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
"http://localhost/path",
|
'http://localhost/path',
|
||||||
[
|
[
|
||||||
"scheme" => "http",
|
'scheme' => 'http',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"path" => "/path"
|
'path' => '/path'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"//localhost/path",
|
'//localhost/path',
|
||||||
[
|
[
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"path" => "/path"
|
'path' => '/path'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"/path",
|
'/path',
|
||||||
[
|
[
|
||||||
"path" => "/path"
|
'path' => '/path'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"/path?cat=molly&dog=bear",
|
'/path?cat=molly&dog=bear',
|
||||||
[
|
[
|
||||||
"path" => "/path",
|
'path' => '/path',
|
||||||
"query" => "cat=molly&dog=bear"
|
'query' => 'cat=molly&dog=bear'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"/path?cat=molly&dog=bear#fragment",
|
'/path?cat=molly&dog=bear#fragment',
|
||||||
[
|
[
|
||||||
"path" => "/path",
|
'path' => '/path',
|
||||||
"query" => "cat=molly&dog=bear",
|
'query' => 'cat=molly&dog=bear',
|
||||||
"fragment" => "fragment"
|
'fragment' => 'fragment'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment",
|
'https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment',
|
||||||
[
|
[
|
||||||
"scheme" => "https",
|
'scheme' => 'https',
|
||||||
"user" => "user",
|
'user' => 'user',
|
||||||
"password" => "password",
|
'password' => 'password',
|
||||||
"host" => "localhost",
|
'host' => 'localhost',
|
||||||
"port" => 4430,
|
'port' => 4430,
|
||||||
"path" => "/path",
|
'path' => '/path',
|
||||||
"query" => "cat=molly&dog=bear",
|
'query' => 'cat=molly&dog=bear',
|
||||||
"fragment" => "fragment"
|
'fragment' => 'fragment'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
// Asterisk Form
|
// Asterisk Form
|
||||||
[
|
[
|
||||||
"*",
|
'*',
|
||||||
[
|
[
|
||||||
"path" => "*"
|
'path' => '*'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
@ -549,36 +549,36 @@ class UriTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
"http://localhost/path",
|
'http://localhost/path',
|
||||||
"http://localhost:80/path"
|
'http://localhost:80/path'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"https://localhost/path",
|
'https://localhost/path',
|
||||||
"https://localhost:443/path"
|
'https://localhost:443/path'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"https://my.sub.sub.domain.com/path",
|
'https://my.sub.sub.domain.com/path',
|
||||||
"https://my.sub.sub.domain.com/path"
|
'https://my.sub.sub.domain.com/path'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment",
|
'https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment',
|
||||||
"https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment"
|
'https://user:password@localhost:4430/path?cat=molly&dog=bear#fragment'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"/path",
|
'/path',
|
||||||
"/path"
|
'/path'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"//double/slash",
|
'//double/slash',
|
||||||
"//double/slash"
|
'//double/slash'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"no/slash",
|
'no/slash',
|
||||||
"no/slash"
|
'no/slash'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"*",
|
'*',
|
||||||
"*"
|
'*'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesMiddlewareWithMatchingMethod()
|
public function testDispatchesMiddlewareWithMatchingMethod()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("GET");
|
$this->request = $this->request->withMethod('GET');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertTrue($this->middleware->called);
|
$this->assertTrue($this->middleware->called);
|
||||||
|
|
@ -47,14 +47,14 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testTreatsMethodNamesCaseSensitively()
|
public function testTreatsMethodNamesCaseSensitively()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("get");
|
$this->request = $this->request->withMethod('get');
|
||||||
|
|
||||||
$middlewareUpper = new MiddlewareMock();
|
$middlewareUpper = new MiddlewareMock();
|
||||||
$middlewareLower = new MiddlewareMock();
|
$middlewareLower = new MiddlewareMock();
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $middlewareUpper);
|
$map->register('GET', $middlewareUpper);
|
||||||
$map->register("get", $middlewareLower);
|
$map->register('get', $middlewareLower);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertTrue($middlewareLower->called);
|
$this->assertTrue($middlewareLower->called);
|
||||||
|
|
@ -62,10 +62,10 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesWildcardMiddlewareWithNonMatchingMethod()
|
public function testDispatchesWildcardMiddlewareWithNonMatchingMethod()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("GET");
|
$this->request = $this->request->withMethod('GET');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("*", $this->middleware);
|
$map->register('*', $this->middleware);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertTrue($this->middleware->called);
|
$this->assertTrue($this->middleware->called);
|
||||||
|
|
@ -73,10 +73,10 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesGetMiddlewareForHeadByDefault()
|
public function testDispatchesGetMiddlewareForHeadByDefault()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("HEAD");
|
$this->request = $this->request->withMethod('HEAD');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertTrue($this->middleware->called);
|
$this->assertTrue($this->middleware->called);
|
||||||
|
|
@ -85,12 +85,12 @@ class MethodMapTest extends TestCase
|
||||||
public function testRegistersMiddlewareForMultipleMethods()
|
public function testRegistersMiddlewareForMultipleMethods()
|
||||||
{
|
{
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET,POST", $this->middleware);
|
$map->register('GET,POST', $this->middleware);
|
||||||
|
|
||||||
$this->request = $this->request->withMethod("GET");
|
$this->request = $this->request->withMethod('GET');
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->request = $this->request->withMethod("POST");
|
$this->request = $this->request->withMethod('POST');
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertEquals(2, $this->middleware->callCount);
|
$this->assertEquals(2, $this->middleware->callCount);
|
||||||
|
|
@ -98,11 +98,11 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testSettingNullDeregistersMiddleware()
|
public function testSettingNullDeregistersMiddleware()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("POST");
|
$this->request = $this->request->withMethod('POST');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("POST", $this->middleware);
|
$map->register('POST', $this->middleware);
|
||||||
$map->register("POST", null);
|
$map->register('POST', null);
|
||||||
$response = $map($this->request, $this->response, $this->next);
|
$response = $map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertEquals(405, $response->getStatusCode());
|
$this->assertEquals(405, $response->getStatusCode());
|
||||||
|
|
@ -110,10 +110,10 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testSetsStatusTo200ForOptions()
|
public function testSetsStatusTo200ForOptions()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("OPTIONS");
|
$this->request = $this->request->withMethod('OPTIONS');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$response = $map($this->request, $this->response, $this->next);
|
$response = $map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
@ -121,10 +121,10 @@ class MethodMapTest extends TestCase
|
||||||
|
|
||||||
public function testStopsPropagatingAfterOptions()
|
public function testStopsPropagatingAfterOptions()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("OPTIONS");
|
$this->request = $this->request->withMethod('OPTIONS');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertFalse($this->next->called);
|
$this->assertFalse($this->next->called);
|
||||||
|
|
@ -133,7 +133,7 @@ class MethodMapTest extends TestCase
|
||||||
/** @dataProvider allowedMethodProvider */
|
/** @dataProvider allowedMethodProvider */
|
||||||
public function testSetsAllowHeaderForOptions($methodsDeclared, $methodsAllowed)
|
public function testSetsAllowHeaderForOptions($methodsDeclared, $methodsAllowed)
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("OPTIONS");
|
$this->request = $this->request->withMethod('OPTIONS');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
|
|
@ -141,16 +141,16 @@ class MethodMapTest extends TestCase
|
||||||
}
|
}
|
||||||
$response = $map($this->request, $this->response, $this->next);
|
$response = $map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine("Allow"));
|
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine('Allow'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider allowedMethodProvider */
|
/** @dataProvider allowedMethodProvider */
|
||||||
public function testSetsStatusTo405ForBadMethod()
|
public function testSetsStatusTo405ForBadMethod()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("POST");
|
$this->request = $this->request->withMethod('POST');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$response = $map($this->request, $this->response, $this->next);
|
$response = $map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertEquals(405, $response->getStatusCode());
|
$this->assertEquals(405, $response->getStatusCode());
|
||||||
|
|
@ -162,10 +162,10 @@ class MethodMapTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testStopsPropagatingAfterBadMethod()
|
public function testStopsPropagatingAfterBadMethod()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("POST");
|
$this->request = $this->request->withMethod('POST');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
$map->register("GET", $this->middleware);
|
$map->register('GET', $this->middleware);
|
||||||
$map($this->request, $this->response, $this->next);
|
$map($this->request, $this->response, $this->next);
|
||||||
$this->assertFalse($this->next->called);
|
$this->assertFalse($this->next->called);
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +173,7 @@ class MethodMapTest extends TestCase
|
||||||
/** @dataProvider allowedMethodProvider */
|
/** @dataProvider allowedMethodProvider */
|
||||||
public function testSetsAllowHeaderForBadMethod($methodsDeclared, $methodsAllowed)
|
public function testSetsAllowHeaderForBadMethod($methodsDeclared, $methodsAllowed)
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withMethod("BAD");
|
$this->request = $this->request->withMethod('BAD');
|
||||||
|
|
||||||
$map = $this->getMethodMap();
|
$map = $this->getMethodMap();
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
|
|
@ -181,17 +181,17 @@ class MethodMapTest extends TestCase
|
||||||
}
|
}
|
||||||
$response = $map($this->request, $this->response, $this->next);
|
$response = $map($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine("Allow"));
|
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine('Allow'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function allowedMethodProvider()
|
public function allowedMethodProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[["GET"], ["GET", "HEAD", "OPTIONS"]],
|
[['GET'], ['GET', 'HEAD', 'OPTIONS']],
|
||||||
[["GET", "POST"], ["GET", "POST", "HEAD", "OPTIONS"]],
|
[['GET', 'POST'], ['GET', 'POST', 'HEAD', 'OPTIONS']],
|
||||||
[["POST"], ["POST", "OPTIONS"]],
|
[['POST'], ['POST', 'OPTIONS']],
|
||||||
[["POST"], ["POST", "OPTIONS"]],
|
[['POST'], ['POST', 'OPTIONS']],
|
||||||
[["GET", "PUT,DELETE"], ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"]],
|
[['GET', 'PUT,DELETE'], ['GET', 'PUT', 'DELETE', 'HEAD', 'OPTIONS']],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class RouterTest extends TestCase
|
||||||
$this->route->__invoke(Argument::cetera())->willReturn(new Response());
|
$this->route->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
$this->route->register(Argument::cetera());
|
$this->route->register(Argument::cetera());
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
$this->route->getTarget()->willReturn("/");
|
$this->route->getTarget()->willReturn('/');
|
||||||
$this->route->getPathVariables()->willReturn([]);
|
$this->route->getPathVariables()->willReturn([]);
|
||||||
|
|
||||||
$this->factory = $this->prophesize(RouteFactory::class);
|
$this->factory = $this->prophesize(RouteFactory::class);
|
||||||
|
|
@ -64,24 +64,24 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testCreatesRouteForTarget()
|
public function testCreatesRouteForTarget()
|
||||||
{
|
{
|
||||||
$this->router->register("GET", "/", "middleware");
|
$this->router->register('GET', '/', 'middleware');
|
||||||
|
|
||||||
$this->factory->create("/")->shouldHaveBeenCalled();
|
$this->factory->create('/')->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDoesNotRecreateRouteForExistingTarget()
|
public function testDoesNotRecreateRouteForExistingTarget()
|
||||||
{
|
{
|
||||||
$this->router->register("GET", "/", "middleware");
|
$this->router->register('GET', '/', 'middleware');
|
||||||
$this->router->register("POST", "/", "middleware");
|
$this->router->register('POST', '/', 'middleware');
|
||||||
|
|
||||||
$this->factory->create("/")->shouldHaveBeenCalledTimes(1);
|
$this->factory->create('/')->shouldHaveBeenCalledTimes(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassesMethodAndMiddlewareToRoute()
|
public function testPassesMethodAndMiddlewareToRoute()
|
||||||
{
|
{
|
||||||
$this->router->register("GET", "/", "middleware");
|
$this->router->register('GET', '/', 'middleware');
|
||||||
|
|
||||||
$this->route->register("GET", "middleware")->shouldHaveBeenCalled();
|
$this->route->register('GET', 'middleware')->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -89,13 +89,13 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesStaticRoute()
|
public function testDispatchesStaticRoute()
|
||||||
{
|
{
|
||||||
$target = "/";
|
$target = '/';
|
||||||
$this->request = $this->request->withRequestTarget($target);
|
$this->request = $this->request->withRequestTarget($target);
|
||||||
|
|
||||||
$this->route->getTarget()->willReturn($target);
|
$this->route->getTarget()->willReturn($target);
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->route->__invoke(Argument::cetera())
|
$this->route->__invoke(Argument::cetera())
|
||||||
|
|
@ -104,13 +104,13 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesPrefixRoute()
|
public function testDispatchesPrefixRoute()
|
||||||
{
|
{
|
||||||
$target = "/animals/cats/*";
|
$target = '/animals/cats/*';
|
||||||
$this->request = $this->request->withRequestTarget("/animals/cats/molly");
|
$this->request = $this->request->withRequestTarget('/animals/cats/molly');
|
||||||
|
|
||||||
$this->route->getTarget()->willReturn($target);
|
$this->route->getTarget()->willReturn($target);
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->route->__invoke(Argument::cetera())
|
$this->route->__invoke(Argument::cetera())
|
||||||
|
|
@ -119,14 +119,14 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testDispatchesPatternRoute()
|
public function testDispatchesPatternRoute()
|
||||||
{
|
{
|
||||||
$target = "/";
|
$target = '/';
|
||||||
$this->request = $this->request->withRequestTarget($target);
|
$this->request = $this->request->withRequestTarget($target);
|
||||||
|
|
||||||
$this->route->getTarget()->willReturn($target);
|
$this->route->getTarget()->willReturn($target);
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->route->__invoke(Argument::cetera())
|
$this->route->__invoke(Argument::cetera())
|
||||||
|
|
@ -137,23 +137,23 @@ class RouterTest extends TestCase
|
||||||
{
|
{
|
||||||
$staticRoute = $this->prophesize(RouteInterface::class);
|
$staticRoute = $this->prophesize(RouteInterface::class);
|
||||||
$staticRoute->register(Argument::cetera());
|
$staticRoute->register(Argument::cetera());
|
||||||
$staticRoute->getTarget()->willReturn("/cats/");
|
$staticRoute->getTarget()->willReturn('/cats/');
|
||||||
$staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
$staticRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$staticRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$prefixRoute = $this->prophesize(RouteInterface::class);
|
$prefixRoute = $this->prophesize(RouteInterface::class);
|
||||||
$prefixRoute->register(Argument::cetera());
|
$prefixRoute->register(Argument::cetera());
|
||||||
$prefixRoute->getTarget()->willReturn("/cats/*");
|
$prefixRoute->getTarget()->willReturn('/cats/*');
|
||||||
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$prefixRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$prefixRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget("/cats/");
|
$this->request = $this->request->withRequestTarget('/cats/');
|
||||||
|
|
||||||
$this->factory->create("/cats/")->willReturn($staticRoute->reveal());
|
$this->factory->create('/cats/')->willReturn($staticRoute->reveal());
|
||||||
$this->factory->create("/cats/*")->willReturn($prefixRoute->reveal());
|
$this->factory->create('/cats/*')->willReturn($prefixRoute->reveal());
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/", "middleware");
|
$this->router->register('GET', '/cats/', 'middleware');
|
||||||
$this->router->register("GET", "/cats/*", "middleware");
|
$this->router->register('GET', '/cats/*', 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$staticRoute->__invoke(Argument::cetera())
|
$staticRoute->__invoke(Argument::cetera())
|
||||||
|
|
@ -166,24 +166,24 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
$shortRoute = $this->prophesize(RouteInterface::class);
|
$shortRoute = $this->prophesize(RouteInterface::class);
|
||||||
$shortRoute->register(Argument::cetera());
|
$shortRoute->register(Argument::cetera());
|
||||||
$shortRoute->getTarget()->willReturn("/animals/*");
|
$shortRoute->getTarget()->willReturn('/animals/*');
|
||||||
$shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$shortRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$shortRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$longRoute = $this->prophesize(RouteInterface::class);
|
$longRoute = $this->prophesize(RouteInterface::class);
|
||||||
$longRoute->register(Argument::cetera());
|
$longRoute->register(Argument::cetera());
|
||||||
$longRoute->getTarget()->willReturn("/animals/cats/*");
|
$longRoute->getTarget()->willReturn('/animals/cats/*');
|
||||||
$longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$longRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$longRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$this->request = $this->request
|
$this->request = $this->request
|
||||||
->withRequestTarget("/animals/cats/molly");
|
->withRequestTarget('/animals/cats/molly');
|
||||||
|
|
||||||
$this->factory->create("/animals/*")->willReturn($shortRoute->reveal());
|
$this->factory->create('/animals/*')->willReturn($shortRoute->reveal());
|
||||||
$this->factory->create("/animals/cats/*")->willReturn($longRoute->reveal());
|
$this->factory->create('/animals/cats/*')->willReturn($longRoute->reveal());
|
||||||
|
|
||||||
$this->router->register("GET", "/animals/*", "middleware");
|
$this->router->register('GET', '/animals/*', 'middleware');
|
||||||
$this->router->register("GET", "/animals/cats/*", "middleware");
|
$this->router->register('GET', '/animals/cats/*', 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$longRoute->__invoke(Argument::cetera())
|
$longRoute->__invoke(Argument::cetera())
|
||||||
|
|
@ -194,23 +194,23 @@ class RouterTest extends TestCase
|
||||||
{
|
{
|
||||||
$prefixRoute = $this->prophesize(RouteInterface::class);
|
$prefixRoute = $this->prophesize(RouteInterface::class);
|
||||||
$prefixRoute->register(Argument::cetera());
|
$prefixRoute->register(Argument::cetera());
|
||||||
$prefixRoute->getTarget()->willReturn("/cats/*");
|
$prefixRoute->getTarget()->willReturn('/cats/*');
|
||||||
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$prefixRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$prefixRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$patternRoute = $this->prophesize(RouteInterface::class);
|
$patternRoute = $this->prophesize(RouteInterface::class);
|
||||||
$patternRoute->register(Argument::cetera());
|
$patternRoute->register(Argument::cetera());
|
||||||
$patternRoute->getTarget()->willReturn("/cats/{id}");
|
$patternRoute->getTarget()->willReturn('/cats/{id}');
|
||||||
$patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
$patternRoute->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget("/cats/");
|
$this->request = $this->request->withRequestTarget('/cats/');
|
||||||
|
|
||||||
$this->factory->create("/cats/*")->willReturn($prefixRoute->reveal());
|
$this->factory->create('/cats/*')->willReturn($prefixRoute->reveal());
|
||||||
$this->factory->create("/cats/{id}")->willReturn($patternRoute->reveal());
|
$this->factory->create('/cats/{id}')->willReturn($patternRoute->reveal());
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/*", "middleware");
|
$this->router->register('GET', '/cats/*', 'middleware');
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register('GET', '/cats/{id}', 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$prefixRoute->__invoke(Argument::cetera())
|
$prefixRoute->__invoke(Argument::cetera())
|
||||||
|
|
@ -221,7 +221,7 @@ class RouterTest extends TestCase
|
||||||
{
|
{
|
||||||
$patternRoute1 = $this->prophesize(RouteInterface::class);
|
$patternRoute1 = $this->prophesize(RouteInterface::class);
|
||||||
$patternRoute1->register(Argument::cetera());
|
$patternRoute1->register(Argument::cetera());
|
||||||
$patternRoute1->getTarget()->willReturn("/cats/{id}");
|
$patternRoute1->getTarget()->willReturn('/cats/{id}');
|
||||||
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute1->getPathVariables()->willReturn([]);
|
$patternRoute1->getPathVariables()->willReturn([]);
|
||||||
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
|
|
@ -229,19 +229,19 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
$patternRoute2 = $this->prophesize(RouteInterface::class);
|
$patternRoute2 = $this->prophesize(RouteInterface::class);
|
||||||
$patternRoute2->register(Argument::cetera());
|
$patternRoute2->register(Argument::cetera());
|
||||||
$patternRoute2->getTarget()->willReturn("/cats/{name}");
|
$patternRoute2->getTarget()->willReturn('/cats/{name}');
|
||||||
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute2->getPathVariables()->willReturn([]);
|
$patternRoute2->getPathVariables()->willReturn([]);
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute2->__invoke(Argument::cetera())->willReturn(new Response());
|
$patternRoute2->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget("/cats/molly");
|
$this->request = $this->request->withRequestTarget('/cats/molly');
|
||||||
|
|
||||||
$this->factory->create("/cats/{id}")->willReturn($patternRoute1->reveal());
|
$this->factory->create('/cats/{id}')->willReturn($patternRoute1->reveal());
|
||||||
$this->factory->create("/cats/{name}")->willReturn($patternRoute2->reveal());
|
$this->factory->create('/cats/{name}')->willReturn($patternRoute2->reveal());
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register('GET', '/cats/{id}', 'middleware');
|
||||||
$this->router->register("GET", "/cats/{name}", "middleware");
|
$this->router->register('GET', '/cats/{name}', 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$patternRoute1->__invoke(Argument::cetera())
|
$patternRoute1->__invoke(Argument::cetera())
|
||||||
|
|
@ -252,7 +252,7 @@ class RouterTest extends TestCase
|
||||||
{
|
{
|
||||||
$patternRoute1 = $this->prophesize(RouteInterface::class);
|
$patternRoute1 = $this->prophesize(RouteInterface::class);
|
||||||
$patternRoute1->register(Argument::cetera());
|
$patternRoute1->register(Argument::cetera());
|
||||||
$patternRoute1->getTarget()->willReturn("/cats/{id}");
|
$patternRoute1->getTarget()->willReturn('/cats/{id}');
|
||||||
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute1->getPathVariables()->willReturn([]);
|
$patternRoute1->getPathVariables()->willReturn([]);
|
||||||
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
|
|
@ -260,19 +260,19 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
$patternRoute2 = $this->prophesize(RouteInterface::class);
|
$patternRoute2 = $this->prophesize(RouteInterface::class);
|
||||||
$patternRoute2->register(Argument::cetera());
|
$patternRoute2->register(Argument::cetera());
|
||||||
$patternRoute2->getTarget()->willReturn("/cats/{name}");
|
$patternRoute2->getTarget()->willReturn('/cats/{name}');
|
||||||
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute2->getPathVariables()->willReturn([]);
|
$patternRoute2->getPathVariables()->willReturn([]);
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute2->__invoke(Argument::cetera())->willReturn(new Response());
|
$patternRoute2->__invoke(Argument::cetera())->willReturn(new Response());
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget("/cats/molly");
|
$this->request = $this->request->withRequestTarget('/cats/molly');
|
||||||
|
|
||||||
$this->factory->create("/cats/{id}")->willReturn($patternRoute1->reveal());
|
$this->factory->create('/cats/{id}')->willReturn($patternRoute1->reveal());
|
||||||
$this->factory->create("/cats/{name}")->willReturn($patternRoute2->reveal());
|
$this->factory->create('/cats/{name}')->willReturn($patternRoute2->reveal());
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register('GET', '/cats/{id}', 'middleware');
|
||||||
$this->router->register("GET", "/cats/{name}", "middleware");
|
$this->router->register('GET', '/cats/{name}', 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())
|
$patternRoute2->matchesRequestTarget(Argument::any())
|
||||||
|
|
@ -281,7 +281,7 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testMatchesPathAgainstRouteWithoutQuery()
|
public function testMatchesPathAgainstRouteWithoutQuery()
|
||||||
{
|
{
|
||||||
$target = "/my/path?cat=molly&dog=bear";
|
$target = '/my/path?cat=molly&dog=bear';
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget($target);
|
$this->request = $this->request->withRequestTarget($target);
|
||||||
|
|
||||||
|
|
@ -289,10 +289,10 @@ class RouterTest extends TestCase
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
|
$this->route->matchesRequestTarget('/my/path')->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -301,10 +301,10 @@ class RouterTest extends TestCase
|
||||||
/** @dataProvider pathVariableProvider */
|
/** @dataProvider pathVariableProvider */
|
||||||
public function testSetPathVariablesAttributeIndividually($name, $value)
|
public function testSetPathVariablesAttributeIndividually($name, $value)
|
||||||
{
|
{
|
||||||
$target = "/";
|
$target = '/';
|
||||||
$variables = [
|
$variables = [
|
||||||
"id" => "1024",
|
'id' => '1024',
|
||||||
"name" => "Molly"
|
'name' => 'Molly'
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget($target);
|
$this->request = $this->request->withRequestTarget($target);
|
||||||
|
|
@ -314,7 +314,7 @@ class RouterTest extends TestCase
|
||||||
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
$this->route->getPathVariables()->willReturn($variables);
|
$this->route->getPathVariables()->willReturn($variables);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$isRequestWithExpectedAttribute = function ($request) use ($name, $value) {
|
$isRequestWithExpectedAttribute = function ($request) use ($name, $value) {
|
||||||
|
|
@ -330,19 +330,19 @@ class RouterTest extends TestCase
|
||||||
public function pathVariableProvider()
|
public function pathVariableProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["id", "1024"],
|
['id', '1024'],
|
||||||
["name", "Molly"]
|
['name', 'Molly']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPathVariablesAttributeAsArray()
|
public function testSetPathVariablesAttributeAsArray()
|
||||||
{
|
{
|
||||||
$attributeName = "pathVariables";
|
$attributeName = 'pathVariables';
|
||||||
|
|
||||||
$target = "/";
|
$target = '/';
|
||||||
$variables = [
|
$variables = [
|
||||||
"id" => "1024",
|
'id' => '1024',
|
||||||
"name" => "Molly"
|
'name' => 'Molly'
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget($target);
|
$this->request = $this->request->withRequestTarget($target);
|
||||||
|
|
@ -353,7 +353,7 @@ class RouterTest extends TestCase
|
||||||
$this->route->getPathVariables()->willReturn($variables);
|
$this->route->getPathVariables()->willReturn($variables);
|
||||||
|
|
||||||
$this->router->__construct(new Dispatcher(), $attributeName);
|
$this->router->__construct(new Dispatcher(), $attributeName);
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register('GET', $target, 'middleware');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
$isRequestWithExpectedAttribute = function ($request) use ($attributeName, $variables) {
|
$isRequestWithExpectedAttribute = function ($request) use ($attributeName, $variables) {
|
||||||
|
|
@ -371,21 +371,21 @@ class RouterTest extends TestCase
|
||||||
|
|
||||||
public function testWhenNoRouteMatchesByDefaultResponds404()
|
public function testWhenNoRouteMatchesByDefaultResponds404()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withRequestTarget("/no/match");
|
$this->request = $this->request->withRequestTarget('/no/match');
|
||||||
$response = $this->router->__invoke($this->request, $this->response, $this->next);
|
$response = $this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
$this->assertEquals(404, $response->getStatusCode());
|
$this->assertEquals(404, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhenNoRouteMatchesByDefaultDoesNotPropagatesToNextMiddleware()
|
public function testWhenNoRouteMatchesByDefaultDoesNotPropagatesToNextMiddleware()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withRequestTarget("/no/match");
|
$this->request = $this->request->withRequestTarget('/no/match');
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
$this->assertFalse($this->next->called);
|
$this->assertFalse($this->next->called);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhenNoRouteMatchesAndContinueModePropagatesToNextMiddleware()
|
public function testWhenNoRouteMatchesAndContinueModePropagatesToNextMiddleware()
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withRequestTarget("/no/match");
|
$this->request = $this->request->withRequestTarget('/no/match');
|
||||||
$this->router->continueOnNotFound();
|
$this->router->continueOnNotFound();
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
$this->assertTrue($this->next->called);
|
$this->assertTrue($this->next->called);
|
||||||
|
|
@ -407,7 +407,7 @@ class RouterTest extends TestCase
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->router->add($middleware);
|
$this->router->add($middleware);
|
||||||
$this->router->register("GET", "/", "Handler");
|
$this->router->register('GET', '/', 'Handler');
|
||||||
|
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
|
|
@ -433,10 +433,10 @@ class RouterTest extends TestCase
|
||||||
return $next($middlewareRequest, $middlewareResponse);
|
return $next($middlewareRequest, $middlewareResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->request = $this->request->withRequestTarget("/no/match");
|
$this->request = $this->request->withRequestTarget('/no/match');
|
||||||
|
|
||||||
$this->router->add($middleware);
|
$this->router->add($middleware);
|
||||||
$this->router->register("GET", "/", "Handler");
|
$this->router->register('GET', '/', 'Handler');
|
||||||
|
|
||||||
$this->router->__invoke($this->request, $this->response, $this->next);
|
$this->router->__invoke($this->request, $this->response, $this->next);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,15 +147,15 @@ class ServerTest extends TestCase
|
||||||
$this->server->setPathVariablesAttributeName('pathVariables');
|
$this->server->setPathVariablesAttributeName('pathVariables');
|
||||||
|
|
||||||
$request = (new ServerRequest())
|
$request = (new ServerRequest())
|
||||||
->withMethod("GET")
|
->withMethod('GET')
|
||||||
->withRequestTarget("/");
|
->withRequestTarget('/');
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$next = function ($rqst, $resp) {
|
$next = function ($rqst, $resp) {
|
||||||
return $resp;
|
return $resp;
|
||||||
};
|
};
|
||||||
|
|
||||||
$router = $this->server->createRouter();
|
$router = $this->server->createRouter();
|
||||||
$router->register("GET", "/", "middleware");
|
$router->register('GET', '/', 'middleware');
|
||||||
$router($request, $response, $next);
|
$router($request, $response, $next);
|
||||||
|
|
||||||
$dispatcher->dispatch(Argument::cetera())
|
$dispatcher->dispatch(Argument::cetera())
|
||||||
|
|
@ -209,7 +209,7 @@ class ServerTest extends TestCase
|
||||||
|
|
||||||
public function testCreatesStockTransmitterByDefault()
|
public function testCreatesStockTransmitterByDefault()
|
||||||
{
|
{
|
||||||
$content = "Hello, world!";
|
$content = 'Hello, world!';
|
||||||
|
|
||||||
$response = (new Response())
|
$response = (new Response())
|
||||||
->withBody(new Stream($content));
|
->withBody(new Stream($content));
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use WellRESTed\Test\TestCase;
|
||||||
use WellRESTed\Transmission\HeaderStack;
|
use WellRESTed\Transmission\HeaderStack;
|
||||||
use WellRESTed\Transmission\Transmitter;
|
use WellRESTed\Transmission\Transmitter;
|
||||||
|
|
||||||
require_once __DIR__ . "/../../../src/HeaderStack.php";
|
require_once __DIR__ . '/../../../src/HeaderStack.php';
|
||||||
|
|
||||||
class TransmitterTest extends TestCase
|
class TransmitterTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ class TransmitterTest extends TestCase
|
||||||
HeaderStack::reset();
|
HeaderStack::reset();
|
||||||
|
|
||||||
$this->request = (new ServerRequest())
|
$this->request = (new ServerRequest())
|
||||||
->withMethod("HEAD");
|
->withMethod('HEAD');
|
||||||
|
|
||||||
$this->body = $this->prophesize(StreamInterface::class);
|
$this->body = $this->prophesize(StreamInterface::class);
|
||||||
$this->body->isReadable()->willReturn(false);
|
$this->body->isReadable()->willReturn(false);
|
||||||
|
|
@ -43,7 +43,7 @@ class TransmitterTest extends TestCase
|
||||||
{
|
{
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
$transmitter->transmit($this->request, $this->response);
|
$transmitter->transmit($this->request, $this->response);
|
||||||
$this->assertContains("HTTP/1.1 200 OK", HeaderStack::getHeaders());
|
$this->assertContains('HTTP/1.1 200 OK', HeaderStack::getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendStatusCodeWithoutReasonPhrase()
|
public function testSendStatusCodeWithoutReasonPhrase()
|
||||||
|
|
@ -52,15 +52,15 @@ class TransmitterTest extends TestCase
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
$transmitter->transmit($this->request, $this->response);
|
$transmitter->transmit($this->request, $this->response);
|
||||||
$this->assertContains("HTTP/1.1 999", HeaderStack::getHeaders());
|
$this->assertContains('HTTP/1.1 999', HeaderStack::getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider headerProvider */
|
/** @dataProvider headerProvider */
|
||||||
public function testSendsHeaders($header)
|
public function testSendsHeaders($header)
|
||||||
{
|
{
|
||||||
$this->response = $this->response
|
$this->response = $this->response
|
||||||
->withHeader("Content-length", ["2048"])
|
->withHeader('Content-length', ['2048'])
|
||||||
->withHeader("X-foo", ["bar", "baz"]);
|
->withHeader('X-foo', ['bar', 'baz']);
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
$transmitter->transmit($this->request, $this->response);
|
$transmitter->transmit($this->request, $this->response);
|
||||||
|
|
@ -70,15 +70,15 @@ class TransmitterTest extends TestCase
|
||||||
public function headerProvider()
|
public function headerProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
["Content-length: 2048"],
|
['Content-length: 2048'],
|
||||||
["X-foo: bar"],
|
['X-foo: bar'],
|
||||||
["X-foo: baz"]
|
['X-foo: baz']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOutputsBody()
|
public function testOutputsBody()
|
||||||
{
|
{
|
||||||
$content = "Hello, world!";
|
$content = 'Hello, world!';
|
||||||
|
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->__toString()->willReturn($content);
|
$this->body->__toString()->willReturn($content);
|
||||||
|
|
@ -96,7 +96,7 @@ class TransmitterTest extends TestCase
|
||||||
|
|
||||||
public function testOutputsBodyInChunks()
|
public function testOutputsBodyInChunks()
|
||||||
{
|
{
|
||||||
$content = "Hello, world!";
|
$content = 'Hello, world!';
|
||||||
$chunkSize = 3;
|
$chunkSize = 3;
|
||||||
$position = 0;
|
$position = 0;
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ class TransmitterTest extends TestCase
|
||||||
|
|
||||||
public function testOutputsUnseekableStreamInChunks()
|
public function testOutputsUnseekableStreamInChunks()
|
||||||
{
|
{
|
||||||
$content = "Hello, world!";
|
$content = 'Hello, world!';
|
||||||
$chunkSize = 3;
|
$chunkSize = 3;
|
||||||
$position = 0;
|
$position = 0;
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ class TransmitterTest extends TestCase
|
||||||
{
|
{
|
||||||
$bodySize = 1024;
|
$bodySize = 1024;
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->__toString()->willReturn("");
|
$this->body->__toString()->willReturn('');
|
||||||
$this->body->getSize()->willReturn($bodySize);
|
$this->body->getSize()->willReturn($bodySize);
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
|
|
@ -182,10 +182,10 @@ class TransmitterTest extends TestCase
|
||||||
$streamSize = 1024;
|
$streamSize = 1024;
|
||||||
$headerSize = 2048;
|
$headerSize = 2048;
|
||||||
|
|
||||||
$this->response = $this->response->withHeader("Content-length", $headerSize);
|
$this->response = $this->response->withHeader('Content-length', $headerSize);
|
||||||
|
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->__toString()->willReturn("");
|
$this->body->__toString()->willReturn('');
|
||||||
$this->body->getSize()->willReturn($streamSize);
|
$this->body->getSize()->willReturn($streamSize);
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
|
|
@ -199,30 +199,30 @@ class TransmitterTest extends TestCase
|
||||||
{
|
{
|
||||||
$bodySize = 1024;
|
$bodySize = 1024;
|
||||||
|
|
||||||
$this->response = $this->response->withHeader("Transfer-encoding", "CHUNKED");
|
$this->response = $this->response->withHeader('Transfer-encoding', 'CHUNKED');
|
||||||
|
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->__toString()->willReturn("");
|
$this->body->__toString()->willReturn('');
|
||||||
$this->body->getSize()->willReturn($bodySize);
|
$this->body->getSize()->willReturn($bodySize);
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
$transmitter->setChunkSize(0);
|
$transmitter->setChunkSize(0);
|
||||||
$transmitter->transmit($this->request, $this->response);
|
$transmitter->transmit($this->request, $this->response);
|
||||||
|
|
||||||
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), "Content-length:");
|
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), 'Content-length:');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDoesNotAddContentLengthHeaderWhenBodySizeIsNull()
|
public function testDoesNotAddContentLengthHeaderWhenBodySizeIsNull()
|
||||||
{
|
{
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->__toString()->willReturn("");
|
$this->body->__toString()->willReturn('');
|
||||||
$this->body->getSize()->willReturn(null);
|
$this->body->getSize()->willReturn(null);
|
||||||
|
|
||||||
$transmitter = new Transmitter();
|
$transmitter = new Transmitter();
|
||||||
$transmitter->setChunkSize(0);
|
$transmitter->setChunkSize(0);
|
||||||
$transmitter->transmit($this->request, $this->response);
|
$transmitter->transmit($this->request, $this->response);
|
||||||
|
|
||||||
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), "Content-length:");
|
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), 'Content-length:');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertArrayDoesNotContainValueWithPrefix($arr, $prefix)
|
private function assertArrayDoesNotContainValueWithPrefix($arr, $prefix)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue