Convert simple string literals to single quotes

This commit is contained in:
PJ Dietz 2020-08-10 07:13:50 -04:00
parent fb18d2ee1e
commit 002bdb7541
28 changed files with 850 additions and 849 deletions

View File

@ -10,4 +10,5 @@ return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'single_quote' => true
]);

View File

@ -18,7 +18,7 @@ class NullStream implements StreamInterface
*/
public function __toString()
{
return "";
return '';
}
/**
@ -96,7 +96,7 @@ class NullStream implements StreamInterface
*/
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()
{
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)
{
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)
{
return "";
return '';
}
/**
@ -168,7 +168,7 @@ class NullStream implements StreamInterface
*/
public function getContents()
{
return "";
return '';
}
/**

View File

@ -89,11 +89,11 @@ class Request extends Message implements RequestInterface
$target = $this->uri->getPath();
$query = $this->uri->getQuery();
if ($query) {
$target .= "?" . $query;
$target .= '?' . $query;
}
// Return "/" if the origin form is empty.
return $target ?: "/";
return $target ?: '/';
}
/**
@ -187,18 +187,18 @@ class Request extends Message implements RequestInterface
$request = clone $this;
$newHost = $uri->getHost();
$oldHost = isset($request->headers["Host"]) ? $request->headers["Host"] : "";
$oldHost = isset($request->headers['Host']) ? $request->headers['Host'] : '';
if ($preserveHost === false) {
// Update Host
if ($newHost && $newHost !== $oldHost) {
unset($request->headers["Host"]);
$request->headers["Host"] = $newHost;
unset($request->headers['Host']);
$request->headers['Host'] = $newHost;
}
} else {
// Preserve Host
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)
{
if (!is_string($method)) {
throw new \InvalidArgumentException("Method must be a string.");
throw new \InvalidArgumentException('Method must be a string.');
}
$method = trim($method);
if (strpos($method, " ") !== false) {
throw new \InvalidArgumentException("Method cannot contain spaces.");
if (strpos($method, ' ') !== false) {
throw new \InvalidArgumentException('Method cannot contain spaces.');
}
return $method;
}

View File

@ -79,7 +79,7 @@ class Response extends Message implements ResponseInterface
* @return static
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus($code, $reasonPhrase = "")
public function withStatus($code, $reasonPhrase = '')
{
$response = clone $this;
$response->statusCode = $code;
@ -111,64 +111,64 @@ class Response extends Message implements ResponseInterface
private function getDefaultReasonPhraseForStatusCode($statusCode)
{
$reasonPhraseLookup = [
100 => "Continue",
101 => "Switching Protocols",
102 => "Processing",
200 => "OK",
201 => "Created",
202 => "Accepted",
203 => "Non-Authoritative Information",
204 => "No Content",
205 => "Reset Content",
206 => "Partial Content",
207 => "Multi-Status",
208 => "Already Reported",
226 => "IM Used",
300 => "Multiple Choices",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
305 => "Use Proxy",
307 => "Temporary Redirect",
308 => "Permanent Redirect",
400 => "Bad Request",
401 => "Unauthorized",
402 => "Payment Required",
403 => "Forbidden",
404 => "Not Found",
405 => "Method Not Allowed",
406 => "Not Acceptable",
407 => "Proxy Authentication Required",
408 => "Request Timeout",
409 => "Conflict",
410 => "Gone",
411 => "Length Required",
412 => "Precondition Failed",
413 => "Payload Too Large",
414 => "URI Too Long",
415 => "Unsupported Media Type",
416 => "Range Not Satisfiable",
417 => "Expectation Failed",
421 => "Misdirected Request",
422 => "Unprocessable Entity",
423 => "Locked",
424 => "Failed Dependency",
426 => "Upgrade Required",
428 => "Precondition Required",
429 => "Too Many Requests",
431 => "Request Header Fields Too Large",
500 => "Internal Server Error",
501 => "Not Implemented",
502 => "Bad Gateway",
503 => "Service Unavailable",
504 => "Gateway Timeout",
505 => "HTTP Version Not Supported",
506 => "Variant Also Negotiates",
507 => "Insufficient Storage",
508 => "Loop Detected",
510 => "Not Extended",
511 => "Network Authentication Required"
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
208 => 'Already Reported',
226 => 'IM Used',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Payload Too Large',
414 => 'URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
421 => 'Misdirected Request',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required'
];
return $reasonPhraseLookup[$statusCode] ?? '';
}

View File

@ -195,7 +195,7 @@ class ServerRequest extends Request implements ServerRequestInterface
{
if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
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)
{
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;
@ -350,15 +350,15 @@ class ServerRequest extends Request implements ServerRequestInterface
$this->readUploadedFiles($_FILES);
$this->queryParams = [];
$this->uri = $this->readUri();
if (isset($_SERVER["QUERY_STRING"])) {
parse_str($_SERVER["QUERY_STRING"], $this->queryParams);
if (isset($_SERVER['QUERY_STRING'])) {
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
$this->protocolVersion = "1.0";
$this->protocolVersion = '1.0';
}
if (isset($_SERVER["REQUEST_METHOD"])) {
$this->method = $_SERVER["REQUEST_METHOD"];
if (isset($_SERVER['REQUEST_METHOD'])) {
$this->method = $_SERVER['REQUEST_METHOD'];
}
$headers = $this->getServerRequestHeaders();
foreach ($headers as $key => $value) {
@ -366,9 +366,9 @@ class ServerRequest extends Request implements ServerRequestInterface
}
$this->body = $this->getStreamForBody();
$contentType = $this->getHeaderLine("Content-type");
if (strpos($contentType, "application/x-www-form-urlencoded") !== false
|| strpos($contentType, "multipart/form-data") !== false) {
$contentType = $this->getHeaderLine('Content-type');
if (strpos($contentType, 'application/x-www-form-urlencoded') !== false
|| strpos($contentType, 'multipart/form-data') !== false) {
$this->parsedBody = $_POST;
}
}
@ -388,37 +388,37 @@ class ServerRequest extends Request implements ServerRequestInterface
array $value
): void {
// 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.
// Check if these items are arrays.
if (is_array($value["name"])
&& is_array($value["type"])
&& is_array($value["tmp_name"])
&& is_array($value["error"])
&& is_array($value["size"])
if (is_array($value['name'])
&& is_array($value['type'])
&& is_array($value['tmp_name'])
&& is_array($value['error'])
&& is_array($value['size'])
) {
// Each item is an array. This is a list of uploaded files.
$files = [];
$keys = array_keys($value["name"]);
$keys = array_keys($value['name']);
foreach ($keys as $key) {
$files[$key] = new UploadedFile(
$value["name"][$key],
$value["type"][$key],
$value["size"][$key],
$value["tmp_name"][$key],
$value["error"][$key]
$value['name'][$key],
$value['type'][$key],
$value['size'][$key],
$value['tmp_name'][$key],
$value['error'][$key]
);
}
$branch[$name] = $files;
} else {
// All expected keys are present and are not arrays. This is an uploaded file.
$uploadedFile = new UploadedFile(
$value["name"],
$value["type"],
$value["size"],
$value["tmp_name"],
$value["error"]
$value['name'],
$value['type'],
$value['size'],
$value['tmp_name'],
$value['error']
);
$branch[$name] = $uploadedFile;
}
@ -434,21 +434,21 @@ class ServerRequest extends Request implements ServerRequestInterface
protected function readUri(): UriInterface
{
$uri = "";
$uri = '';
$scheme = "http";
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && $_SERVER["HTTPS"] !== "off") {
$scheme = "https";
$scheme = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off') {
$scheme = 'https';
}
if (isset($_SERVER["HTTP_HOST"])) {
$authority = $_SERVER["HTTP_HOST"];
if (isset($_SERVER['HTTP_HOST'])) {
$authority = $_SERVER['HTTP_HOST'];
$uri .= "$scheme://$authority";
}
// Path and query string
if (isset($_SERVER["REQUEST_URI"])) {
$uri .= $_SERVER["REQUEST_URI"];
if (isset($_SERVER['REQUEST_URI'])) {
$uri .= $_SERVER['REQUEST_URI'];
}
return new Uri($uri);
@ -478,8 +478,8 @@ class ServerRequest extends Request implements ServerRequestInterface
*/
protected function getStreamForBody()
{
$input = fopen("php://input", "rb");
$temp = fopen("php://temp", "wb+");
$input = fopen('php://input', 'rb');
$temp = fopen('php://temp', 'wb+');
stream_copy_to_stream($input, $temp);
rewind($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
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) === "HTTP_") {
if (substr($name, 0, 5) === 'HTTP_') {
$name = $this->normalizeHeaderName(substr($name, 5));
$headers[$name] = trim($value);
} elseif ($this->isContentHeader($name) && !empty(trim($value))) {
@ -517,8 +517,8 @@ class ServerRequest extends Request implements ServerRequestInterface
*/
private function normalizeHeaderName($name)
{
$name = ucwords(strtolower(str_replace("_", " ", $name)));
return str_replace(" ", "-", $name);
$name = ucwords(strtolower(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.
$keys = array_keys($root);
if (count($keys) !== count(array_filter($keys, "is_string"))) {
if (count($keys) !== count(array_filter($keys, 'is_string'))) {
return false;
}

View File

@ -22,17 +22,17 @@ class Stream implements StreamInterface
* @param resource|string $resource A file system pointer resource or
* 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;
} elseif (is_string($resource)) {
$this->resource = fopen("php://temp", "wb+");
if ($resource !== "") {
$this->resource = fopen('php://temp', 'wb+');
if ($resource !== '') {
$this->write($resource);
}
} 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);
if ($statistics && $statistics["size"]) {
return $statistics["size"];
if ($statistics && $statistics['size']) {
return $statistics['size'];
}
return null;
}
@ -118,12 +118,12 @@ class Stream implements StreamInterface
public function tell()
{
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);
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;
}
@ -153,7 +153,7 @@ class Stream implements StreamInterface
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)
{
if ($this->resource === null) {
throw new \RuntimeException("Unable to seek detached stream.");
throw new \RuntimeException('Unable to seek detached stream.');
}
$result = -1;
@ -180,7 +180,7 @@ class Stream implements StreamInterface
$result = fseek($this->resource, $offset, $whence);
}
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()
{
if ($this->resource === null) {
throw new \RuntimeException("Unable to seek detached stream.");
throw new \RuntimeException('Unable to seek detached stream.');
}
$result = false;
@ -206,7 +206,7 @@ class Stream implements StreamInterface
$result = rewind($this->resource);
}
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)
{
if ($this->resource === null) {
throw new \RuntimeException("Unable to write to detached stream.");
throw new \RuntimeException('Unable to write to detached stream.');
}
$result = false;
@ -243,7 +243,7 @@ class Stream implements StreamInterface
$result = fwrite($this->resource, $string);
}
if ($result === false) {
throw new \RuntimeException("Unable to write to stream.");
throw new \RuntimeException('Unable to write to stream.');
}
return $result;
}
@ -276,7 +276,7 @@ class Stream implements StreamInterface
public function read($length)
{
if ($this->resource === null) {
throw new \RuntimeException("Unable to read to detached stream.");
throw new \RuntimeException('Unable to read to detached stream.');
}
$result = false;
@ -284,7 +284,7 @@ class Stream implements StreamInterface
$result = fread($this->resource, $length);
}
if ($result === false) {
throw new \RuntimeException("Unable to read from stream.");
throw new \RuntimeException('Unable to read from stream.');
}
return $result;
}
@ -299,7 +299,7 @@ class Stream implements StreamInterface
public function getContents()
{
if ($this->resource === null) {
throw new \RuntimeException("Unable to read to detached stream.");
throw new \RuntimeException('Unable to read to detached stream.');
}
$result = false;
@ -307,7 +307,7 @@ class Stream implements StreamInterface
$result = stream_get_contents($this->resource);
}
if ($result === false) {
throw new \RuntimeException("Unable to read from stream.");
throw new \RuntimeException('Unable to read from stream.');
}
return $result;
}

View File

@ -91,13 +91,13 @@ class UploadedFile implements UploadedFileInterface
public function getStream()
{
if ($this->tmpName === null) {
throw new \RuntimeException("Unable to read uploaded file.");
throw new \RuntimeException('Unable to read uploaded file.');
}
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)) {
throw new \RuntimeException("File is not an uploaded file.");
if (php_sapi_name() !== 'cli' && !is_uploaded_file($this->tmpName)) {
throw new \RuntimeException('File is not an uploaded file.');
}
return $this->stream;
}
@ -124,9 +124,9 @@ class UploadedFile implements UploadedFileInterface
public function moveTo($path)
{
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);
} else {
move_uploaded_file($this->tmpName, $path);

View File

@ -21,21 +21,21 @@ class Uri implements UriInterface
const MAX_PORT = 65535;
/** @var string */
private $scheme = "";
private $scheme = '';
/** @var string */
private $user = "";
private $user = '';
/** @var string|null */
private $password;
/** @var string */
private $host = "";
private $host = '';
/** @var int|null */
private $port;
/** @var string */
private $path = "";
private $path = '';
/** @var string */
private $query = "";
private $query = '';
/** @var string */
private $fragment = "";
private $fragment = '';
/**
* @param string $uri A string representation of a URI.
@ -112,15 +112,15 @@ class Uri implements UriInterface
*/
public function getAuthority()
{
$authority = "";
$authority = '';
$host = $this->getHost();
if ($host !== "") {
if ($host !== '') {
// User Info
$userInfo = $this->getUserInfo();
if ($userInfo !== "") {
$authority .= $userInfo . "@";
if ($userInfo !== '') {
$authority .= $userInfo . '@';
}
// Host
@ -130,8 +130,8 @@ class Uri implements UriInterface
$port = $this->getPort();
if ($port !== null) {
$scheme = $this->getScheme();
if (($scheme === "http" && $port !== 80) || ($scheme === "https" && $port !== 443)) {
$authority .= ":" . $port;
if (($scheme === 'http' && $port !== 80) || ($scheme === 'https' && $port !== 443)) {
$authority .= ':' . $port;
}
}
}
@ -158,7 +158,7 @@ class Uri implements UriInterface
{
$userInfo = $this->user;
if ($userInfo && $this->password) {
$userInfo .= ":" . $this->password;
$userInfo .= ':' . $this->password;
}
return $userInfo;
}
@ -198,9 +198,9 @@ class Uri implements UriInterface
{
if ($this->port === null) {
switch ($this->scheme) {
case "http":
case 'http':
return 80;
case "https":
case 'https':
return 443;
default:
return null;
@ -236,7 +236,7 @@ class Uri implements UriInterface
*/
public function getPath()
{
if ($this->path === "*") {
if ($this->path === '*') {
return $this->path;
}
return $this->percentEncode($this->path);
@ -305,9 +305,9 @@ class Uri implements UriInterface
*/
public function withScheme($scheme)
{
$scheme = $scheme ? strtolower($scheme) : "";
if (!in_array($scheme, ["", "http", "https"])) {
throw new \InvalidArgumentException("Scheme must be http, https, or empty.");
$scheme = $scheme ? strtolower($scheme) : '';
if (!in_array($scheme, ['', 'http', 'https'])) {
throw new \InvalidArgumentException('Scheme must be http, https, or empty.');
}
$uri = clone $this;
$uri->scheme = $scheme;
@ -351,7 +351,7 @@ class Uri implements UriInterface
public function withHost($host)
{
if (!is_string($host)) {
throw new \InvalidArgumentException("Host must be a string.");
throw new \InvalidArgumentException('Host must be a string.');
}
$uri = clone $this;
@ -380,12 +380,12 @@ class Uri implements UriInterface
{
if (is_numeric($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);
}
$port = (int) $port;
} 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;
@ -413,7 +413,7 @@ class Uri implements UriInterface
public function withPath($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->path = $path;
@ -488,29 +488,29 @@ class Uri implements UriInterface
*/
public function __toString()
{
$string = "";
$string = '';
$authority = $this->getAuthority();
if ($authority !== "") {
if ($authority !== '') {
$scheme = $this->getScheme();
if ($scheme !== "") {
$string = $scheme . ":";
if ($scheme !== '') {
$string = $scheme . ':';
}
$string .= "//$authority";
}
$path = $this->getPath();
if ($path !== "") {
if ($path !== '') {
$string .= $path;
}
$query = $this->getQuery();
if ($query !== "") {
if ($query !== '') {
$string .= "?$query";
}
$fragment = $this->getFragment();
if ($fragment !== "") {
if ($fragment !== '') {
$string .= "#$fragment";
}

View File

@ -43,8 +43,8 @@ class MethodMap
*/
public function register($method, $dispatchable): void
{
$methods = explode(",", $method);
$methods = array_map("trim", $methods);
$methods = explode(',', $method);
$methods = array_map('trim', $methods);
foreach ($methods as $method) {
$this->map[$method] = $dispatchable;
}
@ -71,18 +71,18 @@ class MethodMap
return $this->dispatchMiddleware($middleware, $request, $response, $next);
}
// For HEAD, dispatch GET by default.
if ($method === "HEAD" && isset($this->map["GET"])) {
$middleware = $this->map["GET"];
if ($method === 'HEAD' && isset($this->map['GET'])) {
$middleware = $this->map['GET'];
return $this->dispatchMiddleware($middleware, $request, $response, $next);
}
// Dispatch * middleware, if registered.
if (isset($this->map["*"])) {
$middleware = $this->map["*"];
if (isset($this->map['*'])) {
$middleware = $this->map['*'];
return $this->dispatchMiddleware($middleware, $request, $response, $next);
}
// Respond describing the allowed methods, either as a 405 response or
// in response to an OPTIONS request.
if ($method === "OPTIONS") {
if ($method === 'OPTIONS') {
$response = $response->withStatus(200);
} else {
$response = $response->withStatus(405);
@ -94,8 +94,8 @@ class MethodMap
private function addAllowHeader(ResponseInterface $response): ResponseInterface
{
$methods = join(",", $this->getAllowedMethods());
return $response->withHeader("Allow", $methods);
$methods = join(',', $this->getAllowedMethods());
return $response->withHeader('Allow', $methods);
}
/**
@ -105,12 +105,12 @@ class MethodMap
{
$methods = array_keys($this->map);
// Add HEAD if GET is allowed and HEAD is not present.
if (in_array("GET", $methods) && !in_array("HEAD", $methods)) {
$methods[] = "HEAD";
if (in_array('GET', $methods) && !in_array('HEAD', $methods)) {
$methods[] = 'HEAD';
}
// Add OPTIONS if not already present.
if (!in_array("OPTIONS", $methods)) {
$methods[] = "OPTIONS";
if (!in_array('OPTIONS', $methods)) {
$methods[] = 'OPTIONS';
}
return $methods;
}

View File

@ -6,7 +6,7 @@ class PrefixRoute extends Route
{
public function __construct(string $target, MethodMap $methodMap)
{
parent::__construct(rtrim($target, "*"), $methodMap);
parent::__construct(rtrim($target, '*'), $methodMap);
}
public function getType(): int

View File

@ -26,7 +26,7 @@ class RegexRoute extends Route
$this->captures = $captures;
return true;
} elseif ($matched === false) {
throw new \RuntimeException("Invalid regular expression: " . $this->getTarget());
throw new \RuntimeException('Invalid regular expression: ' . $this->getTarget());
}
return false;
}

View File

@ -29,12 +29,12 @@ class RouteFactory implements RouteFactoryInterface
*/
public function create($target)
{
if ($target[0] === "/") {
if ($target[0] === '/') {
// Possible static, prefix, or template
// PrefixRoutes end with *
if (substr($target, -1) === "*") {
if (substr($target, -1) === '*') {
return new PrefixRoute($target, new MethodMap($this->dispatcher));
}

View File

@ -53,7 +53,7 @@ class TemplateRoute extends Route
private function matchesStartOfRequestTarget(string $requestTarget): bool
{
$firstVarPos = strpos($this->target, "{");
$firstVarPos = strpos($this->target, '{');
if ($firstVarPos === false) {
return $requestTarget === $this->target;
}
@ -65,7 +65,7 @@ class TemplateRoute extends Route
$variables = [];
// 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.
foreach ($keys as $key) {
@ -73,7 +73,7 @@ class TemplateRoute extends Route
if (isset($this->explosions[$key])) {
$values = explode($this->explosions[$key], $value);
$variables[$key] = array_map("urldecode", $values);
$variables[$key] = array_map('urldecode', $values);
} else {
$value = urldecode($value);
$variables[$key] = $value;
@ -90,16 +90,16 @@ class TemplateRoute extends Route
// Escape allowable characters with regex meaning.
$escape = [
"." => "\\.",
"-" => "\\-",
"+" => "\\+",
"*" => "\\*"
'.' => '\\.',
'-' => '\\-',
'+' => '\\+',
'*' => '\\*'
];
$pattern = str_replace(array_keys($escape), array_values($escape), $pattern);
$unescape = [
"{\\+" => "{+",
"{\\." => "{.",
"\\*}" => "*}"
'{\\+' => '{+',
'{\\.' => '{.',
'\\*}' => '*}'
];
$pattern = str_replace(array_keys($unescape), array_values($unescape), $pattern);
@ -108,7 +108,7 @@ class TemplateRoute extends Route
$pattern = preg_replace_callback(
self::URI_TEMPLATE_EXPRESSION_RE,
[$this, "uriVariableReplacementCallback"],
[$this, 'uriVariableReplacementCallback'],
$pattern
);
@ -120,35 +120,35 @@ class TemplateRoute extends Route
$name = $matches[1];
$pattern = self::RE_UNRESERVED;
$prefix = "";
$delimiter = ",";
$explodeDelimiter = ",";
$prefix = '';
$delimiter = ',';
$explodeDelimiter = ',';
// Read the first character as an operator. This determines which
// characters to allow in the match.
$operator = $name[0];
// Read the last character as the modifier.
$explosion = (substr($name, -1, 1) === "*");
$explosion = (substr($name, -1, 1) === '*');
switch ($operator) {
case "+":
case '+':
$name = substr($name, 1);
$pattern = ".*";
$pattern = '.*';
break;
case ".":
case '.':
$name = substr($name, 1);
$prefix = "\\.";
$delimiter = "\\.";
$explodeDelimiter = ".";
$prefix = '\\.';
$delimiter = '\\.';
$explodeDelimiter = '.';
break;
case "/":
case '/':
$name = substr($name, 1);
$prefix = "\\/";
$delimiter = "\\/";
$prefix = '\\/';
$delimiter = '\\/';
if ($explosion) {
$pattern = '[0-9a-zA-Z\-._\~%,\/]*'; // Unreserved + "," and "/"
$explodeDelimiter = "/";
$explodeDelimiter = '/';
}
break;
}
@ -162,7 +162,7 @@ class TemplateRoute extends Route
$this->explosions[$name] = $explodeDelimiter;
}
$names = explode(",", $name);
$names = explode(',', $name);
$results = [];
foreach ($names as $name) {
$results[] = "(?<{$name}>{$pattern})";

View File

@ -229,7 +229,7 @@ class Router
$this->staticRoutes[$route->getTarget()] = $route;
break;
case RouteInterface::TYPE_PREFIX:
$this->prefixRoutes[rtrim($route->getTarget(), "*")] = $route;
$this->prefixRoutes[rtrim($route->getTarget(), '*')] = $route;
break;
case RouteInterface::TYPE_PATTERN:
$this->patternRoutes[] = $route;

View File

@ -64,12 +64,12 @@ class Transmitter implements TransmitterInterface
// - Response does not have a Transfer-encoding: chunked header
// - Response body stream is readable and reports a non-null size
//
if (!$response->hasHeader("Content-length")
&& !(strtolower($response->getHeaderLine("Transfer-encoding")) === "chunked")
if (!$response->hasHeader('Content-length')
&& !(strtolower($response->getHeaderLine('Transfer-encoding')) === 'chunked')
) {
$size = $response->getBody()->getSize();
if ($size !== null) {
$response = $response->withHeader("Content-length", (string) $size);
$response = $response->withHeader('Content-length', (string) $size);
}
}
return $response;

View File

@ -29,19 +29,19 @@ class DispatchStackTest extends TestCase
$callOrder = [];
$stack = new DispatchStack(new Dispatcher());
$stack->add(function ($request, $response, $next) use (&$callOrder) {
$callOrder[] = "first";
$callOrder[] = 'first';
return $next($request, $response);
});
$stack->add(function ($request, $response, $next) use (&$callOrder) {
$callOrder[] = "second";
$callOrder[] = 'second';
return $next($request, $response);
});
$stack->add(function ($request, $response, $next) use (&$callOrder) {
$callOrder[] = "third";
$callOrder[] = 'third';
return $next($request, $response);
});
$stack($this->request, $this->response, $this->next);
$this->assertEquals(["first", "second", "third"], $callOrder);
$this->assertEquals(['first', 'second', 'third'], $callOrder);
}
public function testCallsNextAfterDispatchingEmptyStack()

View File

@ -10,57 +10,57 @@ class HeaderCollectionTest extends TestCase
public function testAddsSingleHeaderAndIndicatesCaseInsensitiveIsset()
{
$collection = new HeaderCollection();
$collection["Content-Type"] = "application/json";
$this->assertTrue(isset($collection["content-type"]));
$collection['Content-Type'] = 'application/json';
$this->assertTrue(isset($collection['content-type']));
}
public function testAddsMultipleHeadersAndIndicatesCaseInsensitiveIsset()
{
$collection = new HeaderCollection();
$collection["Set-Cookie"] = "cat=Molly";
$collection["SET-COOKIE"] = "dog=Bear";
$this->assertTrue(isset($collection["set-cookie"]));
$collection['Set-Cookie'] = 'cat=Molly';
$collection['SET-COOKIE'] = 'dog=Bear';
$this->assertTrue(isset($collection['set-cookie']));
}
public function testReturnsHeadersWithCaseInsensitiveHeaderName()
{
$collection = new HeaderCollection();
$collection["Set-Cookie"] = "cat=Molly";
$collection["SET-COOKIE"] = "dog=Bear";
$collection['Set-Cookie'] = 'cat=Molly';
$collection['SET-COOKIE'] = 'dog=Bear';
$headers = $collection["set-cookie"];
$this->assertEquals(2, count(array_intersect($headers, ["cat=Molly", "dog=Bear"])));
$headers = $collection['set-cookie'];
$this->assertEquals(2, count(array_intersect($headers, ['cat=Molly', 'dog=Bear'])));
}
public function testRemovesHeadersWithCaseInsensitiveHeaderName()
{
$collection = new HeaderCollection();
$collection["Set-Cookie"] = "cat=Molly";
$collection["SET-COOKIE"] = "dog=Bear";
unset($collection["set-cookie"]);
$this->assertFalse(isset($collection["set-cookie"]));
$collection['Set-Cookie'] = 'cat=Molly';
$collection['SET-COOKIE'] = 'dog=Bear';
unset($collection['set-cookie']);
$this->assertFalse(isset($collection['set-cookie']));
}
/** @coversNothing */
public function testCloneMakesDeepCopyOfHeaders()
{
$collection = new HeaderCollection();
$collection["Set-Cookie"] = "cat=Molly";
$collection['Set-Cookie'] = 'cat=Molly';
$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()
{
$collection = new HeaderCollection();
$collection["Content-length"] = "100";
$collection["Set-Cookie"] = "cat=Molly";
$collection["Set-Cookie"] = "dog=Bear";
$collection["Content-type"] = "application/json";
unset($collection["Content-length"]);
$collection['Content-length'] = '100';
$collection['Set-Cookie'] = 'cat=Molly';
$collection['Set-Cookie'] = 'dog=Bear';
$collection['Content-type'] = 'application/json';
unset($collection['Content-length']);
$headers = [];
@ -68,7 +68,7 @@ class HeaderCollectionTest extends TestCase
$headers[] = $key;
}
$expected = ["Content-type", "Set-Cookie"];
$expected = ['Content-type', 'Set-Cookie'];
$countUnmatched = count(array_diff($expected, $headers)) + count(array_diff($headers, $expected));
$this->assertEquals(0, $countUnmatched);
@ -77,11 +77,11 @@ class HeaderCollectionTest extends TestCase
public function testIteratesWithOriginalKeysAndValues()
{
$collection = new HeaderCollection();
$collection["Content-length"] = "100";
$collection["Set-Cookie"] = "cat=Molly";
$collection["Set-Cookie"] = "dog=Bear";
$collection["Content-type"] = "application/json";
unset($collection["Content-length"]);
$collection['Content-length'] = '100';
$collection['Set-Cookie'] = 'cat=Molly';
$collection['Set-Cookie'] = 'dog=Bear';
$collection['Content-type'] = 'application/json';
unset($collection['Content-length']);
$headers = [];
@ -96,8 +96,8 @@ class HeaderCollectionTest extends TestCase
}
$expected = [
"Set-Cookie" => ["cat=Molly", "dog=Bear"],
"Content-type" => ["application/json"]
'Set-Cookie' => ['cat=Molly', 'dog=Bear'],
'Content-type' => ['application/json']
];
$this->assertEquals($expected, $headers);

View File

@ -11,7 +11,7 @@ class NullStreamTest extends TestCase
public function testCastsToString()
{
$stream = new NullStream();
$this->assertEquals("", (string) $stream);
$this->assertEquals('', (string) $stream);
}
public function testCloseDoesNothing()
@ -75,7 +75,7 @@ class NullStreamTest extends TestCase
{
$this->expectException(RuntimeException::class);
$stream = new NullStream();
$stream->write("");
$stream->write('');
}
public function testIsReadableReturnsTrue()
@ -87,13 +87,13 @@ class NullStreamTest extends TestCase
public function testReadReturnsEmptyString()
{
$stream = new NullStream();
$this->assertEquals("", $stream->read(100));
$this->assertEquals('', $stream->read(100));
}
public function testGetContentsReturnsEmptyString()
{
$stream = new NullStream();
$this->assertEquals("", $stream->getContents());
$this->assertEquals('', $stream->getContents());
}
public function testGetMetadataReturnsNull()
@ -105,6 +105,6 @@ class NullStreamTest extends TestCase
public function testGetMetadataReturnsNullWithKey()
{
$stream = new NullStream();
$this->assertNull($stream->getMetadata("size"));
$this->assertNull($stream->getMetadata('size'));
}
}

View File

@ -61,8 +61,8 @@ class RequestTest extends TestCase
public function testGetRequestTargetPrefersExplicitRequestTarget()
{
$request = new Request();
$request = $request->withRequestTarget("*");
$this->assertEquals("*", $request->getRequestTarget());
$request = $request->withRequestTarget('*');
$this->assertEquals('*', $request->getRequestTarget());
}
public function testGetRequestTargetUsesOriginFormOfUri()
@ -70,20 +70,20 @@ class RequestTest extends TestCase
$uri = new Uri('/my/path?cat=Molly&dog=Bear');
$request = new Request();
$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()
{
$request = new Request();
$this->assertEquals("/", $request->getRequestTarget());
$this->assertEquals('/', $request->getRequestTarget());
}
public function testWithRequestTargetCreatesNewInstance()
{
$request = new Request();
$request = $request->withRequestTarget("*");
$this->assertEquals("*", $request->getRequestTarget());
$request = $request->withRequestTarget('*');
$this->assertEquals('*', $request->getRequestTarget());
}
// ------------------------------------------------------------------------
@ -92,14 +92,14 @@ class RequestTest extends TestCase
public function testGetMethodReturnsGetByDefault()
{
$request = new Request();
$this->assertEquals("GET", $request->getMethod());
$this->assertEquals('GET', $request->getMethod());
}
public function testWithMethodCreatesNewInstance()
{
$request = new Request();
$request = $request->withMethod("POST");
$this->assertEquals("POST", $request->getMethod());
$request = $request->withMethod('POST');
$this->assertEquals('POST', $request->getMethod());
}
/**
@ -117,7 +117,7 @@ class RequestTest extends TestCase
return [
[0],
[false],
["WITH SPACE"]
['WITH SPACE']
];
}
@ -146,44 +146,44 @@ class RequestTest extends TestCase
$request1 = new Request();
$request1 = $request1->withUri($uri1);
$request1 = $request1->withHeader("Accept", "application/json");
$request1 = $request1->withHeader('Accept', 'application/json');
$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()
{
$hostname = "bar.com";
$hostname = 'bar.com';
$uri = new uri("http://$hostname");
$request = new Request();
$request = $request->withHeader("Host", "foo.com");
$request = $request->withHeader('Host', 'foo.com');
$request = $request->withUri($uri);
$this->assertSame([$hostname], $request->getHeader("Host"));
$this->assertSame([$hostname], $request->getHeader('Host'));
}
public function testWithUriDoesNotUpdatesHostHeaderWhenUriHasNoHost()
{
$hostname = "foo.com";
$hostname = 'foo.com';
$uri = new Uri();
$request = new Request();
$request = $request->withHeader("Host", $hostname);
$request = $request->withHeader('Host', $hostname);
$request = $request->withUri($uri);
$this->assertSame([$hostname], $request->getHeader("Host"));
$this->assertSame([$hostname], $request->getHeader('Host'));
}
public function testPreserveHostUpdatesHostHeaderWhenHeaderIsOriginallyMissing()
{
$hostname = "foo.com";
$hostname = 'foo.com';
$uri = new uri("http://$hostname");
$request = new Request();
$request = $request->withUri($uri, true);
$this->assertSame([$hostname], $request->getHeader("Host"));
$this->assertSame([$hostname], $request->getHeader('Host'));
}
public function testPreserveHostDoesNotUpdatesWhenBothAreMissingHosts()
@ -192,17 +192,17 @@ class RequestTest extends TestCase
$request = new Request();
$request = $request->withUri($uri, true);
$this->assertSame([], $request->getHeader("Host"));
$this->assertSame([], $request->getHeader('Host'));
}
public function testPreserveHostDoesNotUpdateHostHeader()
{
$hostname = "foo.com";
$uri = new uri("http://bar.com");
$hostname = 'foo.com';
$uri = new uri('http://bar.com');
$request = new Request();
$request = $request->withHeader("Host", $hostname);
$request = $request->withHeader('Host', $hostname);
$request = $request->withUri($uri, true);
$this->assertSame([$hostname], $request->getHeader("Host"));
$this->assertSame([$hostname], $request->getHeader('Host'));
}
}

View File

@ -20,9 +20,9 @@ class ResponseTest extends TestCase
public function testSetsHeadersOnConstruction()
{
$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()
@ -53,45 +53,45 @@ class ResponseTest extends TestCase
public function statusProvider()
{
return [
[100, null, "Continue"],
[101, null, "Switching Protocols"],
[200, null, "OK"],
[201, null, "Created"],
[202, null, "Accepted"],
[203, null, "Non-Authoritative Information"],
[204, null, "No Content"],
[205, null, "Reset Content"],
[206, null, "Partial Content"],
[300, null, "Multiple Choices"],
[301, null, "Moved Permanently"],
[302, null, "Found"],
[303, null, "See Other"],
[304, null, "Not Modified"],
[305, null, "Use Proxy"],
[400, null, "Bad Request"],
[401, null, "Unauthorized"],
[402, null, "Payment Required"],
[403, null, "Forbidden"],
[404, null, "Not Found"],
[405, null, "Method Not Allowed"],
[406, null, "Not Acceptable"],
[407, null, "Proxy Authentication Required"],
[408, null, "Request Timeout"],
[409, null, "Conflict"],
[410, null, "Gone"],
[411, null, "Length Required"],
[412, null, "Precondition Failed"],
[413, null, "Payload Too Large"],
[414, null, "URI Too Long"],
[415, null, "Unsupported Media Type"],
[500, null, "Internal Server Error"],
[501, null, "Not Implemented"],
[502, null, "Bad Gateway"],
[503, null, "Service Unavailable"],
[504, null, "Gateway Timeout"],
[505, null, "HTTP Version Not Supported"],
[598, null, ""],
[599, "Nonstandard", "Nonstandard"]
[100, null, 'Continue'],
[101, null, 'Switching Protocols'],
[200, null, 'OK'],
[201, null, 'Created'],
[202, null, 'Accepted'],
[203, null, 'Non-Authoritative Information'],
[204, null, 'No Content'],
[205, null, 'Reset Content'],
[206, null, 'Partial Content'],
[300, null, 'Multiple Choices'],
[301, null, 'Moved Permanently'],
[302, null, 'Found'],
[303, null, 'See Other'],
[304, null, 'Not Modified'],
[305, null, 'Use Proxy'],
[400, null, 'Bad Request'],
[401, null, 'Unauthorized'],
[402, null, 'Payment Required'],
[403, null, 'Forbidden'],
[404, null, 'Not Found'],
[405, null, 'Method Not Allowed'],
[406, null, 'Not Acceptable'],
[407, null, 'Proxy Authentication Required'],
[408, null, 'Request Timeout'],
[409, null, 'Conflict'],
[410, null, 'Gone'],
[411, null, 'Length Required'],
[412, null, 'Precondition Failed'],
[413, null, 'Payload Too Large'],
[414, null, 'URI Too Long'],
[415, null, 'Unsupported Media Type'],
[500, null, 'Internal Server Error'],
[501, null, 'Not Implemented'],
[502, null, 'Bad Gateway'],
[503, null, 'Service Unavailable'],
[504, null, 'Gateway Timeout'],
[505, null, 'HTTP Version Not Supported'],
[598, null, ''],
[599, 'Nonstandard', 'Nonstandard']
];
}
@ -99,11 +99,11 @@ class ResponseTest extends TestCase
{
$response1 = new Response();
$response1 = $response1->withStatus(200);
$response1 = $response1->withHeader("Content-type", "application/json");
$response1 = $response1->withHeader('Content-type', 'application/json');
$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'));
}
}

View File

@ -18,19 +18,19 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsFromRequest()
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"HTTP_ACCEPT" => "application/json",
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded",
"QUERY_STRING" => "guinea_pig=Claude&hamster=Fizzgig"
'HTTP_HOST' => 'localhost',
'HTTP_ACCEPT' => 'application/json',
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'QUERY_STRING' => 'guinea_pig=Claude&hamster=Fizzgig'
];
$_COOKIE = [
"cat" => "Molly"
'cat' => 'Molly'
];
$_FILES = [];
$_POST = [
"dog" => "Bear"
'dog' => 'Bear'
];
$attributes = ["guinea_pig" => "Claude"];
$attributes = ['guinea_pig' => 'Claude'];
$request = ServerRequest::getServerRequest($attributes);
$this->assertNotNull($request);
return $request;
@ -46,9 +46,9 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsProtocolVersion($expectedProtocol, $serverProtocol)
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"SERVER_PROTOCOL" => $serverProtocol,
"REQUEST_METHOD" => "GET"
'HTTP_HOST' => 'localhost',
'SERVER_PROTOCOL' => $serverProtocol,
'REQUEST_METHOD' => 'GET'
];
$request = ServerRequest::getServerRequest();
$this->assertEquals($expectedProtocol, $request->getProtocolVersion());
@ -57,10 +57,10 @@ class ServerRequestTest extends TestCase
public function protocolVersionProvider()
{
return [
["1.1", "HTTP/1.1"],
["1.0", "HTTP/1.0"],
["1.1", null],
["1.1", "INVALID"]
['1.1', 'HTTP/1.1'],
['1.0', 'HTTP/1.0'],
['1.1', null],
['1.1', 'INVALID']
];
}
@ -71,8 +71,8 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsMethod($expectedMethod, $serverMethod)
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"REQUEST_METHOD" => $serverMethod
'HTTP_HOST' => 'localhost',
'REQUEST_METHOD' => $serverMethod
];
$request = ServerRequest::getServerRequest();
$this->assertEquals($expectedMethod, $request->getMethod());
@ -81,12 +81,12 @@ class ServerRequestTest extends TestCase
public function methodProvider()
{
return [
["GET", "GET"],
["POST", "POST"],
["DELETE", "DELETE"],
["PUT", "PUT"],
["OPTIONS", "OPTIONS"],
["GET", null]
['GET', 'GET'],
['POST', 'POST'],
['DELETE', 'DELETE'],
['PUT', 'PUT'],
['OPTIONS', 'OPTIONS'],
['GET', null]
];
}
@ -97,8 +97,8 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsRequestTargetFromRequest($expectedRequestTarget, $serverRequestUri)
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"REQUEST_URI" => $serverRequestUri
'HTTP_HOST' => 'localhost',
'REQUEST_URI' => $serverRequestUri
];
$request = ServerRequest::getServerRequest();
$this->assertEquals($expectedRequestTarget, $request->getRequestTarget());
@ -107,10 +107,10 @@ class ServerRequestTest extends TestCase
public function requestTargetProvider()
{
return [
["/", "/"],
["/hello", "/hello"],
["/my/path.txt", "/my/path.txt"],
["/", null]
['/', '/'],
['/hello', '/hello'],
['/my/path.txt', '/my/path.txt'],
['/', null]
];
}
@ -118,7 +118,7 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsHeaders($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()
{
$_SERVER = [
"CONTENT_LENGTH" => "1024",
"CONTENT_TYPE" => "application/json"
'CONTENT_LENGTH' => '1024',
'CONTENT_TYPE' => 'application/json'
];
$request = ServerRequest::getServerRequest();
$this->assertEquals("1024", $request->getHeaderLine("Content-length"));
$this->assertEquals("application/json", $request->getHeaderLine("Content-type"));
$this->assertEquals('1024', $request->getHeaderLine('Content-length'));
$this->assertEquals('application/json', $request->getHeaderLine('Content-type'));
}
/**
@ -141,22 +141,22 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestDoesNotReadEmptyContentHeaders()
{
$_SERVER = [
"CONTENT_LENGTH" => "",
"CONTENT_TYPE" => " "
'CONTENT_LENGTH' => '',
'CONTENT_TYPE' => ' '
];
$request = ServerRequest::getServerRequest();
$this->assertFalse($request->hasHeader("Content-length"));
$this->assertFalse($request->hasHeader("Content-type"));
$this->assertFalse($request->hasHeader('Content-length'));
$this->assertFalse($request->hasHeader('Content-type'));
}
public function testGetServerRequestReadsBody()
{
$body = new NullStream();
$request = $this->getMockBuilder('WellRESTed\Message\ServerRequest')
->setMethods(["getStreamForBody"])
->setMethods(['getStreamForBody'])
->getMock();
$request->expects($this->any())
->method("getStreamForBody")
->method('getStreamForBody')
->will($this->returnValue($body));
$called = false;
@ -185,30 +185,30 @@ class ServerRequestTest extends TestCase
{
return [
[
new Uri("http://localhost/path"),
new Uri('http://localhost/path'),
[
"HTTPS" => "off",
"HTTP_HOST" => "localhost",
"REQUEST_URI" => "/path",
"QUERY_STRING" => ""
'HTTPS' => 'off',
'HTTP_HOST' => 'localhost',
'REQUEST_URI' => '/path',
'QUERY_STRING' => ''
]
],
[
new Uri("https://foo.com/path/to/stuff?cat=molly"),
new Uri('https://foo.com/path/to/stuff?cat=molly'),
[
"HTTPS" => "1",
"HTTP_HOST" => "foo.com",
"REQUEST_URI" => "/path/to/stuff?cat=molly",
"QUERY_STRING" => "cat=molly"
'HTTPS' => '1',
'HTTP_HOST' => 'foo.com',
'REQUEST_URI' => '/path/to/stuff?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_HOST" => "foo.com:8080",
"REQUEST_URI" => "/path/to/stuff?cat=molly",
"QUERY_STRING" => "cat=molly"
'HTTP' => '1',
'HTTP_HOST' => 'foo.com:8080',
'REQUEST_URI' => '/path/to/stuff?cat=molly',
'QUERY_STRING' => 'cat=molly'
]
]
];
@ -221,21 +221,21 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestReadsServerParams($request)
{
/** @var ServerRequest $request */
$this->assertEquals("localhost", $request->getServerParams()["HTTP_HOST"]);
$this->assertEquals('localhost', $request->getServerParams()['HTTP_HOST']);
}
/** @depends testGetServerRequestReadsFromRequest */
public function testGetServerRequestReadsCookieParams($request)
{
/** @var ServerRequest $request */
$this->assertEquals("Molly", $request->getCookieParams()["cat"]);
$this->assertEquals('Molly', $request->getCookieParams()['cat']);
}
/** @depends testGetServerRequestReadsFromRequest */
public function testGetServerRequestReadsQueryParams($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)
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"HTTP_ACCEPT" => "application/json",
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded"
'HTTP_HOST' => 'localhost',
'HTTP_ACCEPT' => 'application/json',
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
];
$_FILES = [
"single" => [
"name" => "single.txt",
"type" => "text/plain",
"tmp_name" => "/tmp/php9hNlHe",
"error" => UPLOAD_ERR_OK,
"size" => 524
'single' => [
'name' => 'single.txt',
'type' => 'text/plain',
'tmp_name' => '/tmp/php9hNlHe',
'error' => UPLOAD_ERR_OK,
'size' => 524
],
"nested" => [
"level2" => [
"name" => "nested.json",
"type" => "application/json",
"tmp_name" => "/tmp/phpadhjk",
"error" => UPLOAD_ERR_OK,
"size" => 1024
'nested' => [
'level2' => [
'name' => 'nested.json',
'type' => 'application/json',
'tmp_name' => '/tmp/phpadhjk',
'error' => UPLOAD_ERR_OK,
'size' => 1024
]
],
"nestedList" => [
"level2" => [
"name" => [
0 => "nestedList0.jpg",
1 => "nestedList1.jpg",
2 => ""
'nestedList' => [
'level2' => [
'name' => [
0 => 'nestedList0.jpg',
1 => 'nestedList1.jpg',
2 => ''
],
"type" => [
0 => "image/jpeg",
1 => "image/jpeg",
2 => ""
'type' => [
0 => 'image/jpeg',
1 => 'image/jpeg',
2 => ''
],
"tmp_name" => [
0 => "/tmp/phpjpg0",
1 => "/tmp/phpjpg1",
2 => ""
'tmp_name' => [
0 => '/tmp/phpjpg0',
1 => '/tmp/phpjpg1',
2 => ''
],
"error" => [
'error' => [
0 => UPLOAD_ERR_OK,
1 => UPLOAD_ERR_OK,
2 => UPLOAD_ERR_NO_FILE
],
"size" => [
'size' => [
0 => 256,
1 => 4096,
2 => 0
]
]
],
"nestedDictionary" => [
"level2" => [
"name" => [
"file0" => "nestedDictionary0.jpg",
"file1" => "nestedDictionary1.jpg"
'nestedDictionary' => [
'level2' => [
'name' => [
'file0' => 'nestedDictionary0.jpg',
'file1' => 'nestedDictionary1.jpg'
],
"type" => [
"file0" => "image/png",
"file1" => "image/png"
'type' => [
'file0' => 'image/png',
'file1' => 'image/png'
],
"tmp_name" => [
"file0" => "/tmp/phppng0",
"file1" => "/tmp/phppng1"
'tmp_name' => [
'file0' => '/tmp/phppng0',
'file1' => '/tmp/phppng1'
],
"error" => [
"file0" => UPLOAD_ERR_OK,
"file1" => UPLOAD_ERR_OK
'error' => [
'file0' => UPLOAD_ERR_OK,
'file1' => UPLOAD_ERR_OK
],
"size" => [
"file0" => 256,
"file1" => 4096
'size' => [
'file0' => 256,
'file1' => 4096
]
]
]
@ -331,13 +331,13 @@ class ServerRequestTest extends TestCase
public function uploadedFileProvider()
{
return [
[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("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("", "", 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("nestedDictionary1.jpg", "image/png", 4096, "/tmp/phppngg1", UPLOAD_ERR_OK), ["nestedDictionary", "level2", "file1"]]
[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('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('', '', 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('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)
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"HTTP_CONTENT_TYPE" => $contentType,
'HTTP_HOST' => 'localhost',
'HTTP_CONTENT_TYPE' => $contentType,
];
$_COOKIE = [];
$_FILES = [];
$_POST = [
"dog" => "Bear"
'dog' => 'Bear'
];
$request = ServerRequest::getServerRequest();
$this->assertEquals("Bear", $request->getParsedBody()["dog"]);
$this->assertEquals('Bear', $request->getParsedBody()['dog']);
}
public function formContentTypeProvider()
{
return [
["application/x-www-form-urlencoded"],
["multipart/form-data"]
['application/x-www-form-urlencoded'],
['multipart/form-data']
];
}
@ -372,7 +372,7 @@ class ServerRequestTest extends TestCase
public function testGetServerRequestProvidesAttributesIfPassed($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 */
$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 */
$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()
{
$_SERVER = [
"HTTP_HOST" => "localhost",
"HTTP_ACCEPT" => "application/json",
"HTTP_CONTENT_TYPE" => "application/x-www-form-urlencoded"
'HTTP_HOST' => 'localhost',
'HTTP_ACCEPT' => 'application/json',
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
];
$_FILES = [];
$request = ServerRequest::getServerRequest();
@ -447,7 +447,7 @@ class ServerRequestTest extends TestCase
public function testWithUploadedFilesCreatesNewInstance()
{
$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();
$request1 = $request->withUploadedFiles([]);
@ -467,20 +467,20 @@ class ServerRequestTest extends TestCase
{
return [
[[]],
[["files" => new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)]],
[["nested" => [
"level2" => new UploadedFile("index.html", "text/html", 524, "/tmp/php9hNlHe", 0)
[['files' => new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)]],
[['nested' => [
'level2' => new UploadedFile('index.html', 'text/html', 524, '/tmp/php9hNlHe', 0)
]]],
[["nestedList" => [
"level2" => [
new UploadedFile("file1.html", "text/html", 524, "/tmp/php9hNlHe", 0),
new UploadedFile("file2.html", "text/html", 524, "/tmp/php9hNshj", 0)
[['nestedList' => [
'level2' => [
new UploadedFile('file1.html', 'text/html', 524, '/tmp/php9hNlHe', 0),
new UploadedFile('file2.html', 'text/html', 524, '/tmp/php9hNshj', 0)
]
]]],
[["nestedDictionary" => [
"level2" => [
"file1" => new UploadedFile("file1.html", "text/html", 524, "/tmp/php9hNlHe", 0),
"file2" => new UploadedFile("file2.html", "text/html", 524, "/tmp/php9hNshj", 0)
[['nestedDictionary' => [
'level2' => [
'file1' => new UploadedFile('file1.html', 'text/html', 524, '/tmp/php9hNlHe', 0),
'file2' => new UploadedFile('file2.html', 'text/html', 524, '/tmp/php9hNshj', 0)
]
]]]
];
@ -500,53 +500,53 @@ class ServerRequestTest extends TestCase
{
return [
// 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("index2.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)]
],
[
"single" => [
"name" => "single.txt",
"type" => "text/plain",
"tmp_name" => "/tmp/php9hNlHe",
"error" => UPLOAD_ERR_OK,
"size" => 524
'single' => [
'name' => 'single.txt',
'type' => 'text/plain',
'tmp_name' => '/tmp/php9hNlHe',
'error' => UPLOAD_ERR_OK,
'size' => 524
],
"nested" => [
"level2" => [
"name" => "nested.json",
"type" => "application/json",
"tmp_name" => "/tmp/phpadhjk",
"error" => UPLOAD_ERR_OK,
"size" => 1024
'nested' => [
'level2' => [
'name' => 'nested.json',
'type' => 'application/json',
'tmp_name' => '/tmp/phpadhjk',
'error' => UPLOAD_ERR_OK,
'size' => 1024
]
]
],
[
"nestedList" => [
"level2" => [
"name" => [
0 => "nestedList0.jpg",
1 => "nestedList1.jpg",
2 => ""
'nestedList' => [
'level2' => [
'name' => [
0 => 'nestedList0.jpg',
1 => 'nestedList1.jpg',
2 => ''
],
"type" => [
0 => "image/jpeg",
1 => "image/jpeg",
2 => ""
'type' => [
0 => 'image/jpeg',
1 => 'image/jpeg',
2 => ''
],
"tmp_name" => [
0 => "/tmp/phpjpg0",
1 => "/tmp/phpjpg1",
2 => ""
'tmp_name' => [
0 => '/tmp/phpjpg0',
1 => '/tmp/phpjpg1',
2 => ''
],
"error" => [
'error' => [
0 => UPLOAD_ERR_OK,
1 => UPLOAD_ERR_OK,
2 => UPLOAD_ERR_NO_FILE
],
"size" => [
'size' => [
0 => 256,
1 => 4096,
2 => 0
@ -573,7 +573,7 @@ class ServerRequestTest extends TestCase
$body1 = $request1->getParsedBody();
$request2 = $request1->withParsedBody([
"guinea_pig" => "Clyde"
'guinea_pig' => 'Clyde'
]);
$body2 = $request2->getParsedBody();
@ -601,12 +601,12 @@ class ServerRequestTest extends TestCase
public function testCloneMakesDeepCopiesOfParsedBody()
{
$body = (object) [
"cat" => "Dog"
'cat' => 'Dog'
];
$request1 = new ServerRequest();
$request1 = $request1->withParsedBody($body);
$request2 = $request1->withHeader("X-extra", "hello world");
$request2 = $request1->withHeader('X-extra', 'hello world');
$this->assertTrue(
$request1->getParsedBody() == $request2->getParsedBody()
@ -626,11 +626,11 @@ class ServerRequestTest extends TestCase
public function testGetAttributesReturnsAllAttributes()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$request = $request->withAttribute("dog", "Bear");
$request = $request->withAttribute('cat', 'Molly');
$request = $request->withAttribute('dog', 'Bear');
$expected = [
"cat" => "Molly",
"dog" => "Bear"
'cat' => 'Molly',
'dog' => 'Bear'
];
$this->assertEquals($expected, $request->getAttributes());
}
@ -638,24 +638,24 @@ class ServerRequestTest extends TestCase
public function testGetAttributeReturnsDefaultIfNotSet()
{
$request = new ServerRequest();
$this->assertEquals("Oscar", $request->getAttribute("cat", "Oscar"));
$this->assertEquals('Oscar', $request->getAttribute('cat', 'Oscar'));
}
public function testWithAttributeCreatesNewInstance()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$this->assertEquals("Molly", $request->getAttribute("cat"));
$request = $request->withAttribute('cat', 'Molly');
$this->assertEquals('Molly', $request->getAttribute('cat'));
}
public function testWithAttributePreserversOtherAttributes()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$request = $request->withAttribute("dog", "Bear");
$request = $request->withAttribute('cat', 'Molly');
$request = $request->withAttribute('dog', 'Bear');
$expected = [
"cat" => "Molly",
"dog" => "Bear"
'cat' => 'Molly',
'dog' => 'Bear'
];
$this->assertEquals($expected, $request->getAttributes());
}
@ -663,24 +663,24 @@ class ServerRequestTest extends TestCase
public function testWithoutAttributeCreatesNewInstance()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$this->assertNotEquals($request, $request->withoutAttribute("cat"));
$request = $request->withAttribute('cat', 'Molly');
$this->assertNotEquals($request, $request->withoutAttribute('cat'));
}
public function testWithoutAttributeRemovesAttribute()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$request = $request->withoutAttribute("cat");
$this->assertEquals("Oscar", $request->getAttribute("cat", "Oscar"));
$request = $request->withAttribute('cat', 'Molly');
$request = $request->withoutAttribute('cat');
$this->assertEquals('Oscar', $request->getAttribute('cat', 'Oscar'));
}
public function testWithoutAttributePreservesOtherAttributes()
{
$request = new ServerRequest();
$request = $request->withAttribute("cat", "Molly");
$request = $request->withAttribute("dog", "Bear");
$request = $request->withoutAttribute("cat");
$this->assertEquals("Bear", $request->getAttribute("dog"));
$request = $request->withAttribute('cat', 'Molly');
$request = $request->withAttribute('dog', 'Bear');
$request = $request->withoutAttribute('cat');
$this->assertEquals('Bear', $request->getAttribute('dog'));
}
}

View File

@ -11,12 +11,12 @@ class StreamTest extends TestCase
{
private $resource;
private $resourceDevNull;
private $content = "Hello, world!";
private $content = 'Hello, world!';
protected function setUp(): void
{
$this->resource = fopen("php://memory", "w+");
$this->resourceDevNull = fopen("/dev/null", "r");
$this->resource = fopen('php://memory', 'w+');
$this->resourceDevNull = fopen('/dev/null', 'r');
fwrite($this->resource, $this->content);
}
@ -35,7 +35,7 @@ class StreamTest extends TestCase
public function testCreatesInstanceWithString()
{
$stream = new Stream("Hello, world!");
$stream = new Stream('Hello, world!');
$this->assertNotNull($stream);
}
@ -123,7 +123,7 @@ class StreamTest extends TestCase
{
$stream = new Stream($this->resource);
$metadata = stream_get_meta_data($this->resource);
$seekable = $metadata["seekable"] == 1;
$seekable = $metadata['seekable'] == 1;
$this->assertEquals($seekable, $stream->isSeekable());
}
@ -167,17 +167,17 @@ class StreamTest extends TestCase
public function testThrowsExceptionOnErrorWriting()
{
$this->expectException(RuntimeException::class);
$filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "r");
$filename = tempnam(sys_get_temp_dir(), 'php');
$handle = fopen($filename, 'r');
$stream = new Stream($handle);
$stream->write("Hello, world!");
$stream->write('Hello, world!');
}
public function testThrowsExceptionOnErrorReading()
{
$this->expectException(RuntimeException::class);
$filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "w");
$filename = tempnam(sys_get_temp_dir(), 'php');
$handle = fopen($filename, 'w');
$stream = new Stream($handle);
$stream->read(10);
}
@ -187,14 +187,14 @@ class StreamTest extends TestCase
$stream = new Stream($this->resource);
$stream->seek(7);
$string = $stream->read(5);
$this->assertEquals("world", $string);
$this->assertEquals('world', $string);
}
public function testThrowsExceptionOnErrorReadingToEnd()
{
$this->expectException(RuntimeException::class);
$filename = tempnam(sys_get_temp_dir(), "php");
$handle = fopen($filename, "w");
$filename = tempnam(sys_get_temp_dir(), 'php');
$handle = fopen($filename, 'w');
$stream = new Stream($handle);
$stream->getContents();
}
@ -204,7 +204,7 @@ class StreamTest extends TestCase
$stream = new Stream($this->resource);
$stream->seek(7);
$string = $stream->getContents();
$this->assertEquals("world!", $string);
$this->assertEquals('world!', $string);
}
public function testReturnsMetadataArray()
@ -217,7 +217,7 @@ class StreamTest extends TestCase
{
$stream = new Stream($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)
{
$tmp = tempnam(sys_get_temp_dir(), "php");
if ($mode[0] === "x") {
$tmp = tempnam(sys_get_temp_dir(), 'php');
if ($mode[0] === 'x') {
unlink($tmp);
}
$resource = fopen($tmp, $mode);
@ -245,8 +245,8 @@ class StreamTest extends TestCase
*/
public function testReturnsIsWritableForWritableStreams($mode, $readable, $writable)
{
$tmp = tempnam(sys_get_temp_dir(), "php");
if ($mode[0] === "x") {
$tmp = tempnam(sys_get_temp_dir(), 'php');
if ($mode[0] === 'x') {
unlink($tmp);
}
$resource = fopen($tmp, $mode);
@ -257,16 +257,16 @@ class StreamTest extends TestCase
public function modeProvider()
{
return [
["r", true, false],
["r+", true, true],
["w", false, true],
["w+", true, true],
["a", false, true],
["a+", true, true],
["x", false, true],
["x+", true, true],
["c", false, true],
["c+", true, true]
['r', true, false],
['r+', true, true],
['w', false, true],
['w+', true, true],
['a', false, true],
['a+', true, true],
['x', false, true],
['x+', true, true],
['c', false, true],
['c+', true, true]
];
}

View File

@ -9,7 +9,7 @@ use WellRESTed\Message\UploadedFileState;
use WellRESTed\Test\TestCase;
// Hides several php core functions for testing.
require_once __DIR__ . "/../../../src/UploadedFileState.php";
require_once __DIR__ . '/../../../src/UploadedFileState.php';
class UploadedFileTest extends TestCase
{
@ -19,9 +19,9 @@ class UploadedFileTest extends TestCase
public function setUp(): void
{
parent::setUp();
UploadedFileState::$php_sapi_name = "cli";
$this->tmpName = tempnam(sys_get_temp_dir(), "tst");
$this->movePath = tempnam(sys_get_temp_dir(), "tst");
UploadedFileState::$php_sapi_name = 'cli';
$this->tmpName = tempnam(sys_get_temp_dir(), 'tst');
$this->movePath = tempnam(sys_get_temp_dir(), 'tst');
}
public function tearDown(): void
@ -40,22 +40,22 @@ class UploadedFileTest extends TestCase
public function testGetStreamReturnsStreamInterface()
{
$file = new UploadedFile("", "", 0, $this->tmpName, 0);
$file = new UploadedFile('', '', 0, $this->tmpName, 0);
$this->assertInstanceOf(StreamInterface::class, $file->getStream());
}
public function testGetStreamReturnsStreamWrappingUploadedFile()
{
$content = "Hello, World!";
$content = 'Hello, World!';
file_put_contents($this->tmpName, $content);
$file = new UploadedFile("", "", 0, $this->tmpName, "");
$file = new UploadedFile('', '', 0, $this->tmpName, '');
$stream = $file->getStream();
$this->assertEquals($content, (string) $stream);
}
public function testGetStreamThrowsRuntimeExceptionForNoFile()
{
$file = new UploadedFile("", "", 0, "", 0);
$file = new UploadedFile('', '', 0, '', 0);
$this->expectException(RuntimeException::class);
$file->getStream();
}
@ -63,9 +63,9 @@ class UploadedFileTest extends TestCase
public function testGetStreamThrowsExceptionAfterMoveTo()
{
$this->expectException(RuntimeException::class);
$content = "Hello, World!";
$content = 'Hello, World!';
file_put_contents($this->tmpName, $content);
$file = new UploadedFile("", "", 0, $this->tmpName, "");
$file = new UploadedFile('', '', 0, $this->tmpName, '');
$file->moveTo($this->movePath);
$file->getStream();
}
@ -73,9 +73,9 @@ class UploadedFileTest extends TestCase
public function testGetStreamThrowsExceptionForNonUploadedFile()
{
$this->expectException(RuntimeException::class);
UploadedFileState::$php_sapi_name = "apache";
UploadedFileState::$php_sapi_name = 'apache';
UploadedFileState::$is_uploaded_file = false;
$file = new UploadedFile("", "", 0, "", 0);
$file = new UploadedFile('', '', 0, '', 0);
$file->getStream();
}
@ -84,13 +84,13 @@ class UploadedFileTest extends TestCase
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);
$originalMd5 = md5_file($this->tmpName);
$file = new UploadedFile("", "", 0, $this->tmpName, "");
$file = new UploadedFile('', '', 0, $this->tmpName, '');
$file->moveTo($this->movePath);
$this->assertEquals($originalMd5, md5_file($this->movePath));
@ -98,11 +98,11 @@ class UploadedFileTest extends TestCase
public function testMoveToNonSapiRelocatesUploadedFileToDestinationIfExists()
{
$content = "Hello, World!";
$content = 'Hello, World!';
file_put_contents($this->tmpName, $content);
$originalMd5 = md5_file($this->tmpName);
$file = new UploadedFile("", "", 0, $this->tmpName, "");
$file = new UploadedFile('', '', 0, $this->tmpName, '');
$file->moveTo($this->movePath);
$this->assertEquals($originalMd5, md5_file($this->movePath));
@ -112,10 +112,10 @@ class UploadedFileTest extends TestCase
{
$this->expectException(RuntimeException::class);
$content = "Hello, World!";
$content = 'Hello, World!';
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);
}
@ -125,7 +125,7 @@ class UploadedFileTest extends TestCase
public function testGetSizeReturnsSize()
{
$file = new UploadedFile("", "", 1024, "", 0);
$file = new UploadedFile('', '', 1024, '', 0);
$this->assertEquals(1024, $file->getSize());
}
@ -134,7 +134,7 @@ class UploadedFileTest extends TestCase
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());
}
@ -143,8 +143,8 @@ class UploadedFileTest extends TestCase
public function testGetClientFilenameReturnsClientFilename()
{
$file = new UploadedFile("clientFilename", "", 0, "", 0);
$this->assertEquals("clientFilename", $file->getClientFilename());
$file = new UploadedFile('clientFilename', '', 0, '', 0);
$this->assertEquals('clientFilename', $file->getClientFilename());
}
// ------------------------------------------------------------------------
@ -152,7 +152,7 @@ class UploadedFileTest extends TestCase
public function testGetClientMediaTypeReturnsClientMediaType()
{
$file = new UploadedFile("", "clientMediaType", 0, "", 0);
$this->assertEquals("clientMediaType", $file->getClientMediaType());
$file = new UploadedFile('', 'clientMediaType', 0, '', 0);
$this->assertEquals('clientMediaType', $file->getClientMediaType());
}
}

View File

@ -14,7 +14,7 @@ class UriTest extends TestCase
public function testDefaultSchemeIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getScheme());
$this->assertSame('', $uri->getScheme());
}
/** @dataProvider schemeProvider */
@ -28,12 +28,12 @@ class UriTest extends TestCase
public function schemeProvider()
{
return [
["http", "http"],
["https", "https"],
["http", "HTTP"],
["https", "HTTPS"],
["", null],
["", ""]
['http', 'http'],
['https', 'https'],
['http', 'HTTP'],
['https', 'HTTPS'],
['', null],
['', '']
];
}
@ -41,7 +41,7 @@ class UriTest extends TestCase
{
$this->expectException(InvalidArgumentException::class);
$uri = new Uri();
$uri->withScheme("gopher");
$uri->withScheme('gopher');
}
// ------------------------------------------------------------------------
@ -50,7 +50,7 @@ class UriTest extends TestCase
public function testDefaultAuthorityIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getAuthority());
$this->assertSame('', $uri->getAuthority());
}
public function testRespectsMyAuthoritah()
@ -63,25 +63,25 @@ class UriTest extends TestCase
{
$uri = new Uri();
if (isset($components["scheme"])) {
$uri = $uri->withScheme($components["scheme"]);
if (isset($components['scheme'])) {
$uri = $uri->withScheme($components['scheme']);
}
if (isset($components["user"])) {
$user = $components["user"];
if (isset($components['user'])) {
$user = $components['user'];
$password = null;
if (isset($components["password"])) {
$password = $components["password"];
if (isset($components['password'])) {
$password = $components['password'];
}
$uri = $uri->withUserInfo($user, $password);
}
if (isset($components["host"])) {
$uri = $uri->withHost($components["host"]);
if (isset($components['host'])) {
$uri = $uri->withHost($components['host']);
}
if (isset($components["port"])) {
$uri = $uri->withPort($components["port"]);
if (isset($components['port'])) {
$uri = $uri->withPort($components['port']);
}
$this->assertEquals($expected, $uri->getAuthority());
@ -91,73 +91,73 @@ class UriTest extends TestCase
{
return [
[
"localhost",
'localhost',
[
"host" => "localhost"
'host' => 'localhost'
]
],
[
"user@localhost",
'user@localhost',
[
"host" => "localhost",
"user" => "user"
'host' => 'localhost',
'user' => 'user'
]
],
[
"user:password@localhost",
'user:password@localhost',
[
"host" => "localhost",
"user" => "user",
"password" => "password"
'host' => 'localhost',
'user' => 'user',
'password' => 'password'
]
],
[
"localhost",
'localhost',
[
"host" => "localhost",
"password" => "password"
'host' => 'localhost',
'password' => 'password'
]
],
[
"localhost",
'localhost',
[
"scheme" => "http",
"host" => "localhost",
"port" => 80
'scheme' => 'http',
'host' => 'localhost',
'port' => 80
]
],
[
"localhost",
'localhost',
[
"scheme" => "https",
"host" => "localhost",
"port" => 443
'scheme' => 'https',
'host' => 'localhost',
'port' => 443
]
],
[
"localhost:4430",
'localhost:4430',
[
"scheme" => "https",
"host" => "localhost",
"port" => 4430
'scheme' => 'https',
'host' => 'localhost',
'port' => 4430
]
],
[
"localhost:8080",
'localhost:8080',
[
"scheme" => "http",
"host" => "localhost",
"port" => 8080
'scheme' => 'http',
'host' => 'localhost',
'port' => 8080
]
],
[
"user:password@localhost:4430",
'user:password@localhost:4430',
[
"scheme" => "https",
"user" => "user",
"password" => "password",
"host" => "localhost",
"port" => 4430
'scheme' => 'https',
'user' => 'user',
'password' => 'password',
'host' => 'localhost',
'port' => 4430
]
],
];
@ -169,7 +169,7 @@ class UriTest extends TestCase
public function testDefaultUserInfoIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getUserInfo());
$this->assertSame('', $uri->getUserInfo());
}
/**
@ -189,11 +189,11 @@ class UriTest extends TestCase
public function userInfoProvider()
{
return [
["user:password", "user", "password"],
["user", "user", ""],
["user", "user", null],
["", "", "password"],
["", "", ""]
['user:password', 'user', 'password'],
['user', 'user', ''],
['user', 'user', null],
['', '', 'password'],
['', '', '']
];
}
@ -203,7 +203,7 @@ class UriTest extends TestCase
public function testDefaultHostIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getHost());
$this->assertSame('', $uri->getHost());
}
/** @dataProvider hostProvider */
@ -217,10 +217,10 @@ class UriTest extends TestCase
public function hostProvider()
{
return [
["", ""],
["localhost", "localhost"],
["localhost", "LOCALHOST"],
["foo.com", "FOO.com"]
['', ''],
['localhost', 'localhost'],
['localhost', 'LOCALHOST'],
['foo.com', 'FOO.com']
];
}
@ -255,13 +255,13 @@ class UriTest extends TestCase
public function testDefaultPortForHttpSchemeIs80()
{
$uri = new Uri();
$this->assertSame(80, $uri->withScheme("http")->getPort());
$this->assertSame(80, $uri->withScheme('http')->getPort());
}
public function testDefaultPortForHttpsSchemeIs443()
{
$uri = new Uri();
$this->assertSame(443, $uri->withScheme("https")->getPort());
$this->assertSame(443, $uri->withScheme('https')->getPort());
}
/** @dataProvider portAndSchemeProvider */
@ -275,12 +275,12 @@ class UriTest extends TestCase
public function portAndSchemeProvider()
{
return [
[null, "", null],
[80, "http", null],
[443, "https", null],
[8080, "", 8080],
[8080, "http", "8080"],
[8080, "https", 8080.0]
[null, '', null],
[80, 'http', null],
[443, 'https', null],
[8080, '', 8080],
[8080, 'http', '8080'],
[8080, 'https', 8080.0]
];
}
@ -300,7 +300,7 @@ class UriTest extends TestCase
[true],
[-1],
[65536],
["dog"]
['dog']
];
}
@ -310,7 +310,7 @@ class UriTest extends TestCase
public function testDefaultPathIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getPath());
$this->assertSame('', $uri->getPath());
}
/** @dataProvider pathProvider */
@ -333,13 +333,13 @@ class UriTest extends TestCase
public function pathProvider()
{
return [
["", ""],
["/", "/"],
["*", "*"],
["/my/path", "/my/path"],
["/encoded%2Fslash", "/encoded%2Fslash"],
["/percent/%25", "/percent/%"],
["/%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "/áéíóú"]
['', ''],
['/', '/'],
['*', '*'],
['/my/path', '/my/path'],
['/encoded%2Fslash', '/encoded%2Fslash'],
['/percent/%25', '/percent/%'],
['/%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', '/áéíóú']
];
}
@ -349,7 +349,7 @@ class UriTest extends TestCase
public function testDefaultQueryIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getQuery());
$this->assertSame('', $uri->getQuery());
}
/** @dataProvider queryProvider */
@ -372,9 +372,9 @@ class UriTest extends TestCase
public function queryProvider()
{
return [
["cat=molly", "cat=molly"],
["cat=molly&dog=bear", "cat=molly&dog=bear"],
["accents=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "accents=áéíóú"]
['cat=molly', 'cat=molly'],
['cat=molly&dog=bear', 'cat=molly&dog=bear'],
['accents=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', 'accents=áéíóú']
];
}
@ -403,7 +403,7 @@ class UriTest extends TestCase
public function testDefaultFragmentIsEmpty()
{
$uri = new Uri();
$this->assertSame("", $uri->getFragment());
$this->assertSame('', $uri->getFragment());
}
/** @dataProvider fragmentProvider */
@ -426,9 +426,9 @@ class UriTest extends TestCase
public function fragmentProvider()
{
return [
["", null],
["molly", "molly"],
["%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA", "áéíóú"]
['', null],
['molly', 'molly'],
['%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA', 'áéíóú']
];
}
@ -440,37 +440,37 @@ class UriTest extends TestCase
{
$uri = new Uri();
if (isset($components["scheme"])) {
$uri = $uri->withScheme($components["scheme"]);
if (isset($components['scheme'])) {
$uri = $uri->withScheme($components['scheme']);
}
if (isset($components["user"])) {
$user = $components["user"];
if (isset($components['user'])) {
$user = $components['user'];
$password = null;
if (isset($components["password"])) {
$password = $components["password"];
if (isset($components['password'])) {
$password = $components['password'];
}
$uri = $uri->withUserInfo($user, $password);
}
if (isset($components["host"])) {
$uri = $uri->withHost($components["host"]);
if (isset($components['host'])) {
$uri = $uri->withHost($components['host']);
}
if (isset($components["port"])) {
$uri = $uri->withPort($components["port"]);
if (isset($components['port'])) {
$uri = $uri->withPort($components['port']);
}
if (isset($components["path"])) {
$uri = $uri->withPath($components["path"]);
if (isset($components['path'])) {
$uri = $uri->withPath($components['path']);
}
if (isset($components["query"])) {
$uri = $uri->withQuery($components["query"]);
if (isset($components['query'])) {
$uri = $uri->withQuery($components['query']);
}
if (isset($components["fragment"])) {
$uri = $uri->withFragment($components["fragment"]);
if (isset($components['fragment'])) {
$uri = $uri->withFragment($components['fragment']);
}
$this->assertEquals($expected, (string) $uri);
@ -480,59 +480,59 @@ class UriTest extends TestCase
{
return [
[
"http://localhost/path",
'http://localhost/path',
[
"scheme" => "http",
"host" => "localhost",
"path" => "/path"
'scheme' => 'http',
'host' => 'localhost',
'path' => '/path'
]
],
[
"//localhost/path",
'//localhost/path',
[
"host" => "localhost",
"path" => "/path"
'host' => 'localhost',
'path' => '/path'
]
],
[
"/path",
'/path',
[
"path" => "/path"
'path' => '/path'
]
],
[
"/path?cat=molly&dog=bear",
'/path?cat=molly&dog=bear',
[
"path" => "/path",
"query" => "cat=molly&dog=bear"
'path' => '/path',
'query' => 'cat=molly&dog=bear'
]
],
[
"/path?cat=molly&dog=bear#fragment",
'/path?cat=molly&dog=bear#fragment',
[
"path" => "/path",
"query" => "cat=molly&dog=bear",
"fragment" => "fragment"
'path' => '/path',
'query' => 'cat=molly&dog=bear',
'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",
"user" => "user",
"password" => "password",
"host" => "localhost",
"port" => 4430,
"path" => "/path",
"query" => "cat=molly&dog=bear",
"fragment" => "fragment"
'scheme' => 'https',
'user' => 'user',
'password' => 'password',
'host' => 'localhost',
'port' => 4430,
'path' => '/path',
'query' => 'cat=molly&dog=bear',
'fragment' => 'fragment'
]
],
// Asterisk Form
[
"*",
'*',
[
"path" => "*"
'path' => '*'
]
],
];
@ -549,36 +549,36 @@ class UriTest extends TestCase
{
return [
[
"http://localhost/path",
"http://localhost:80/path"
'http://localhost/path',
'http://localhost:80/path'
],
[
"https://localhost/path",
"https://localhost:443/path"
'https://localhost/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'
],
[
"*",
"*"
'*',
'*'
]
];
}

View File

@ -36,10 +36,10 @@ class MethodMapTest extends TestCase
public function testDispatchesMiddlewareWithMatchingMethod()
{
$this->request = $this->request->withMethod("GET");
$this->request = $this->request->withMethod('GET');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$map($this->request, $this->response, $this->next);
$this->assertTrue($this->middleware->called);
@ -47,14 +47,14 @@ class MethodMapTest extends TestCase
public function testTreatsMethodNamesCaseSensitively()
{
$this->request = $this->request->withMethod("get");
$this->request = $this->request->withMethod('get');
$middlewareUpper = new MiddlewareMock();
$middlewareLower = new MiddlewareMock();
$map = $this->getMethodMap();
$map->register("GET", $middlewareUpper);
$map->register("get", $middlewareLower);
$map->register('GET', $middlewareUpper);
$map->register('get', $middlewareLower);
$map($this->request, $this->response, $this->next);
$this->assertTrue($middlewareLower->called);
@ -62,10 +62,10 @@ class MethodMapTest extends TestCase
public function testDispatchesWildcardMiddlewareWithNonMatchingMethod()
{
$this->request = $this->request->withMethod("GET");
$this->request = $this->request->withMethod('GET');
$map = $this->getMethodMap();
$map->register("*", $this->middleware);
$map->register('*', $this->middleware);
$map($this->request, $this->response, $this->next);
$this->assertTrue($this->middleware->called);
@ -73,10 +73,10 @@ class MethodMapTest extends TestCase
public function testDispatchesGetMiddlewareForHeadByDefault()
{
$this->request = $this->request->withMethod("HEAD");
$this->request = $this->request->withMethod('HEAD');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$map($this->request, $this->response, $this->next);
$this->assertTrue($this->middleware->called);
@ -85,12 +85,12 @@ class MethodMapTest extends TestCase
public function testRegistersMiddlewareForMultipleMethods()
{
$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);
$this->request = $this->request->withMethod("POST");
$this->request = $this->request->withMethod('POST');
$map($this->request, $this->response, $this->next);
$this->assertEquals(2, $this->middleware->callCount);
@ -98,11 +98,11 @@ class MethodMapTest extends TestCase
public function testSettingNullDeregistersMiddleware()
{
$this->request = $this->request->withMethod("POST");
$this->request = $this->request->withMethod('POST');
$map = $this->getMethodMap();
$map->register("POST", $this->middleware);
$map->register("POST", null);
$map->register('POST', $this->middleware);
$map->register('POST', null);
$response = $map($this->request, $this->response, $this->next);
$this->assertEquals(405, $response->getStatusCode());
@ -110,10 +110,10 @@ class MethodMapTest extends TestCase
public function testSetsStatusTo200ForOptions()
{
$this->request = $this->request->withMethod("OPTIONS");
$this->request = $this->request->withMethod('OPTIONS');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$response = $map($this->request, $this->response, $this->next);
$this->assertEquals(200, $response->getStatusCode());
@ -121,10 +121,10 @@ class MethodMapTest extends TestCase
public function testStopsPropagatingAfterOptions()
{
$this->request = $this->request->withMethod("OPTIONS");
$this->request = $this->request->withMethod('OPTIONS');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$map($this->request, $this->response, $this->next);
$this->assertFalse($this->next->called);
@ -133,7 +133,7 @@ class MethodMapTest extends TestCase
/** @dataProvider allowedMethodProvider */
public function testSetsAllowHeaderForOptions($methodsDeclared, $methodsAllowed)
{
$this->request = $this->request->withMethod("OPTIONS");
$this->request = $this->request->withMethod('OPTIONS');
$map = $this->getMethodMap();
foreach ($methodsDeclared as $method) {
@ -141,16 +141,16 @@ class MethodMapTest extends TestCase
}
$response = $map($this->request, $this->response, $this->next);
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine("Allow"));
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine('Allow'));
}
/** @dataProvider allowedMethodProvider */
public function testSetsStatusTo405ForBadMethod()
{
$this->request = $this->request->withMethod("POST");
$this->request = $this->request->withMethod('POST');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$response = $map($this->request, $this->response, $this->next);
$this->assertEquals(405, $response->getStatusCode());
@ -162,10 +162,10 @@ class MethodMapTest extends TestCase
*/
public function testStopsPropagatingAfterBadMethod()
{
$this->request = $this->request->withMethod("POST");
$this->request = $this->request->withMethod('POST');
$map = $this->getMethodMap();
$map->register("GET", $this->middleware);
$map->register('GET', $this->middleware);
$map($this->request, $this->response, $this->next);
$this->assertFalse($this->next->called);
}
@ -173,7 +173,7 @@ class MethodMapTest extends TestCase
/** @dataProvider allowedMethodProvider */
public function testSetsAllowHeaderForBadMethod($methodsDeclared, $methodsAllowed)
{
$this->request = $this->request->withMethod("BAD");
$this->request = $this->request->withMethod('BAD');
$map = $this->getMethodMap();
foreach ($methodsDeclared as $method) {
@ -181,17 +181,17 @@ class MethodMapTest extends TestCase
}
$response = $map($this->request, $this->response, $this->next);
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine("Allow"));
$this->assertContainsEach($methodsAllowed, $response->getHeaderLine('Allow'));
}
public function allowedMethodProvider()
{
return [
[["GET"], ["GET", "HEAD", "OPTIONS"]],
[["GET", "POST"], ["GET", "POST", "HEAD", "OPTIONS"]],
[["POST"], ["POST", "OPTIONS"]],
[["POST"], ["POST", "OPTIONS"]],
[["GET", "PUT,DELETE"], ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"]],
[['GET'], ['GET', 'HEAD', 'OPTIONS']],
[['GET', 'POST'], ['GET', 'POST', 'HEAD', 'OPTIONS']],
[['POST'], ['POST', 'OPTIONS']],
[['POST'], ['POST', 'OPTIONS']],
[['GET', 'PUT,DELETE'], ['GET', 'PUT', 'DELETE', 'HEAD', 'OPTIONS']],
];
}

View File

@ -34,7 +34,7 @@ class RouterTest extends TestCase
$this->route->__invoke(Argument::cetera())->willReturn(new Response());
$this->route->register(Argument::cetera());
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
$this->route->getTarget()->willReturn("/");
$this->route->getTarget()->willReturn('/');
$this->route->getPathVariables()->willReturn([]);
$this->factory = $this->prophesize(RouteFactory::class);
@ -64,24 +64,24 @@ class RouterTest extends TestCase
public function testCreatesRouteForTarget()
{
$this->router->register("GET", "/", "middleware");
$this->router->register('GET', '/', 'middleware');
$this->factory->create("/")->shouldHaveBeenCalled();
$this->factory->create('/')->shouldHaveBeenCalled();
}
public function testDoesNotRecreateRouteForExistingTarget()
{
$this->router->register("GET", "/", "middleware");
$this->router->register("POST", "/", "middleware");
$this->router->register('GET', '/', 'middleware');
$this->router->register('POST', '/', 'middleware');
$this->factory->create("/")->shouldHaveBeenCalledTimes(1);
$this->factory->create('/')->shouldHaveBeenCalledTimes(1);
}
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()
{
$target = "/";
$target = '/';
$this->request = $this->request->withRequestTarget($target);
$this->route->getTarget()->willReturn($target);
$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->route->__invoke(Argument::cetera())
@ -104,13 +104,13 @@ class RouterTest extends TestCase
public function testDispatchesPrefixRoute()
{
$target = "/animals/cats/*";
$this->request = $this->request->withRequestTarget("/animals/cats/molly");
$target = '/animals/cats/*';
$this->request = $this->request->withRequestTarget('/animals/cats/molly');
$this->route->getTarget()->willReturn($target);
$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->route->__invoke(Argument::cetera())
@ -119,14 +119,14 @@ class RouterTest extends TestCase
public function testDispatchesPatternRoute()
{
$target = "/";
$target = '/';
$this->request = $this->request->withRequestTarget($target);
$this->route->getTarget()->willReturn($target);
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$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->route->__invoke(Argument::cetera())
@ -137,23 +137,23 @@ class RouterTest extends TestCase
{
$staticRoute = $this->prophesize(RouteInterface::class);
$staticRoute->register(Argument::cetera());
$staticRoute->getTarget()->willReturn("/cats/");
$staticRoute->getTarget()->willReturn('/cats/');
$staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC);
$staticRoute->__invoke(Argument::cetera())->willReturn(new Response());
$prefixRoute = $this->prophesize(RouteInterface::class);
$prefixRoute->register(Argument::cetera());
$prefixRoute->getTarget()->willReturn("/cats/*");
$prefixRoute->getTarget()->willReturn('/cats/*');
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
$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($prefixRoute->reveal());
$this->factory->create('/cats/')->willReturn($staticRoute->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);
$staticRoute->__invoke(Argument::cetera())
@ -166,24 +166,24 @@ class RouterTest extends TestCase
$shortRoute = $this->prophesize(RouteInterface::class);
$shortRoute->register(Argument::cetera());
$shortRoute->getTarget()->willReturn("/animals/*");
$shortRoute->getTarget()->willReturn('/animals/*');
$shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
$shortRoute->__invoke(Argument::cetera())->willReturn(new Response());
$longRoute = $this->prophesize(RouteInterface::class);
$longRoute->register(Argument::cetera());
$longRoute->getTarget()->willReturn("/animals/cats/*");
$longRoute->getTarget()->willReturn('/animals/cats/*');
$longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
$longRoute->__invoke(Argument::cetera())->willReturn(new Response());
$this->request = $this->request
->withRequestTarget("/animals/cats/molly");
->withRequestTarget('/animals/cats/molly');
$this->factory->create("/animals/*")->willReturn($shortRoute->reveal());
$this->factory->create("/animals/cats/*")->willReturn($longRoute->reveal());
$this->factory->create('/animals/*')->willReturn($shortRoute->reveal());
$this->factory->create('/animals/cats/*')->willReturn($longRoute->reveal());
$this->router->register("GET", "/animals/*", "middleware");
$this->router->register("GET", "/animals/cats/*", "middleware");
$this->router->register('GET', '/animals/*', 'middleware');
$this->router->register('GET', '/animals/cats/*', 'middleware');
$this->router->__invoke($this->request, $this->response, $this->next);
$longRoute->__invoke(Argument::cetera())
@ -194,23 +194,23 @@ class RouterTest extends TestCase
{
$prefixRoute = $this->prophesize(RouteInterface::class);
$prefixRoute->register(Argument::cetera());
$prefixRoute->getTarget()->willReturn("/cats/*");
$prefixRoute->getTarget()->willReturn('/cats/*');
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
$prefixRoute->__invoke(Argument::cetera())->willReturn(new Response());
$patternRoute = $this->prophesize(RouteInterface::class);
$patternRoute->register(Argument::cetera());
$patternRoute->getTarget()->willReturn("/cats/{id}");
$patternRoute->getTarget()->willReturn('/cats/{id}');
$patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$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/{id}")->willReturn($patternRoute->reveal());
$this->factory->create('/cats/*')->willReturn($prefixRoute->reveal());
$this->factory->create('/cats/{id}')->willReturn($patternRoute->reveal());
$this->router->register("GET", "/cats/*", "middleware");
$this->router->register("GET", "/cats/{id}", "middleware");
$this->router->register('GET', '/cats/*', 'middleware');
$this->router->register('GET', '/cats/{id}', 'middleware');
$this->router->__invoke($this->request, $this->response, $this->next);
$prefixRoute->__invoke(Argument::cetera())
@ -221,7 +221,7 @@ class RouterTest extends TestCase
{
$patternRoute1 = $this->prophesize(RouteInterface::class);
$patternRoute1->register(Argument::cetera());
$patternRoute1->getTarget()->willReturn("/cats/{id}");
$patternRoute1->getTarget()->willReturn('/cats/{id}');
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$patternRoute1->getPathVariables()->willReturn([]);
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
@ -229,19 +229,19 @@ class RouterTest extends TestCase
$patternRoute2 = $this->prophesize(RouteInterface::class);
$patternRoute2->register(Argument::cetera());
$patternRoute2->getTarget()->willReturn("/cats/{name}");
$patternRoute2->getTarget()->willReturn('/cats/{name}');
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$patternRoute2->getPathVariables()->willReturn([]);
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
$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/{name}")->willReturn($patternRoute2->reveal());
$this->factory->create('/cats/{id}')->willReturn($patternRoute1->reveal());
$this->factory->create('/cats/{name}')->willReturn($patternRoute2->reveal());
$this->router->register("GET", "/cats/{id}", "middleware");
$this->router->register("GET", "/cats/{name}", "middleware");
$this->router->register('GET', '/cats/{id}', 'middleware');
$this->router->register('GET', '/cats/{name}', 'middleware');
$this->router->__invoke($this->request, $this->response, $this->next);
$patternRoute1->__invoke(Argument::cetera())
@ -252,7 +252,7 @@ class RouterTest extends TestCase
{
$patternRoute1 = $this->prophesize(RouteInterface::class);
$patternRoute1->register(Argument::cetera());
$patternRoute1->getTarget()->willReturn("/cats/{id}");
$patternRoute1->getTarget()->willReturn('/cats/{id}');
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$patternRoute1->getPathVariables()->willReturn([]);
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
@ -260,19 +260,19 @@ class RouterTest extends TestCase
$patternRoute2 = $this->prophesize(RouteInterface::class);
$patternRoute2->register(Argument::cetera());
$patternRoute2->getTarget()->willReturn("/cats/{name}");
$patternRoute2->getTarget()->willReturn('/cats/{name}');
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$patternRoute2->getPathVariables()->willReturn([]);
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
$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/{name}")->willReturn($patternRoute2->reveal());
$this->factory->create('/cats/{id}')->willReturn($patternRoute1->reveal());
$this->factory->create('/cats/{name}')->willReturn($patternRoute2->reveal());
$this->router->register("GET", "/cats/{id}", "middleware");
$this->router->register("GET", "/cats/{name}", "middleware");
$this->router->register('GET', '/cats/{id}', 'middleware');
$this->router->register('GET', '/cats/{name}', 'middleware');
$this->router->__invoke($this->request, $this->response, $this->next);
$patternRoute2->matchesRequestTarget(Argument::any())
@ -281,7 +281,7 @@ class RouterTest extends TestCase
public function testMatchesPathAgainstRouteWithoutQuery()
{
$target = "/my/path?cat=molly&dog=bear";
$target = '/my/path?cat=molly&dog=bear';
$this->request = $this->request->withRequestTarget($target);
@ -289,10 +289,10 @@ class RouterTest extends TestCase
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$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->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
$this->route->matchesRequestTarget('/my/path')->shouldHaveBeenCalled();
}
// ------------------------------------------------------------------------
@ -301,10 +301,10 @@ class RouterTest extends TestCase
/** @dataProvider pathVariableProvider */
public function testSetPathVariablesAttributeIndividually($name, $value)
{
$target = "/";
$target = '/';
$variables = [
"id" => "1024",
"name" => "Molly"
'id' => '1024',
'name' => 'Molly'
];
$this->request = $this->request->withRequestTarget($target);
@ -314,7 +314,7 @@ class RouterTest extends TestCase
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
$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);
$isRequestWithExpectedAttribute = function ($request) use ($name, $value) {
@ -330,19 +330,19 @@ class RouterTest extends TestCase
public function pathVariableProvider()
{
return [
["id", "1024"],
["name", "Molly"]
['id', '1024'],
['name', 'Molly']
];
}
public function testSetPathVariablesAttributeAsArray()
{
$attributeName = "pathVariables";
$attributeName = 'pathVariables';
$target = "/";
$target = '/';
$variables = [
"id" => "1024",
"name" => "Molly"
'id' => '1024',
'name' => 'Molly'
];
$this->request = $this->request->withRequestTarget($target);
@ -353,7 +353,7 @@ class RouterTest extends TestCase
$this->route->getPathVariables()->willReturn($variables);
$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);
$isRequestWithExpectedAttribute = function ($request) use ($attributeName, $variables) {
@ -371,21 +371,21 @@ class RouterTest extends TestCase
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);
$this->assertEquals(404, $response->getStatusCode());
}
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->assertFalse($this->next->called);
}
public function testWhenNoRouteMatchesAndContinueModePropagatesToNextMiddleware()
{
$this->request = $this->request->withRequestTarget("/no/match");
$this->request = $this->request->withRequestTarget('/no/match');
$this->router->continueOnNotFound();
$this->router->__invoke($this->request, $this->response, $this->next);
$this->assertTrue($this->next->called);
@ -407,7 +407,7 @@ class RouterTest extends TestCase
};
$this->router->add($middleware);
$this->router->register("GET", "/", "Handler");
$this->router->register('GET', '/', 'Handler');
$this->router->__invoke($this->request, $this->response, $this->next);
@ -433,10 +433,10 @@ class RouterTest extends TestCase
return $next($middlewareRequest, $middlewareResponse);
};
$this->request = $this->request->withRequestTarget("/no/match");
$this->request = $this->request->withRequestTarget('/no/match');
$this->router->add($middleware);
$this->router->register("GET", "/", "Handler");
$this->router->register('GET', '/', 'Handler');
$this->router->__invoke($this->request, $this->response, $this->next);

View File

@ -147,15 +147,15 @@ class ServerTest extends TestCase
$this->server->setPathVariablesAttributeName('pathVariables');
$request = (new ServerRequest())
->withMethod("GET")
->withRequestTarget("/");
->withMethod('GET')
->withRequestTarget('/');
$response = new Response();
$next = function ($rqst, $resp) {
return $resp;
};
$router = $this->server->createRouter();
$router->register("GET", "/", "middleware");
$router->register('GET', '/', 'middleware');
$router($request, $response, $next);
$dispatcher->dispatch(Argument::cetera())
@ -209,7 +209,7 @@ class ServerTest extends TestCase
public function testCreatesStockTransmitterByDefault()
{
$content = "Hello, world!";
$content = 'Hello, world!';
$response = (new Response())
->withBody(new Stream($content));

View File

@ -11,7 +11,7 @@ use WellRESTed\Test\TestCase;
use WellRESTed\Transmission\HeaderStack;
use WellRESTed\Transmission\Transmitter;
require_once __DIR__ . "/../../../src/HeaderStack.php";
require_once __DIR__ . '/../../../src/HeaderStack.php';
class TransmitterTest extends TestCase
{
@ -26,7 +26,7 @@ class TransmitterTest extends TestCase
HeaderStack::reset();
$this->request = (new ServerRequest())
->withMethod("HEAD");
->withMethod('HEAD');
$this->body = $this->prophesize(StreamInterface::class);
$this->body->isReadable()->willReturn(false);
@ -43,7 +43,7 @@ class TransmitterTest extends TestCase
{
$transmitter = new Transmitter();
$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()
@ -52,15 +52,15 @@ class TransmitterTest extends TestCase
$transmitter = new Transmitter();
$transmitter->transmit($this->request, $this->response);
$this->assertContains("HTTP/1.1 999", HeaderStack::getHeaders());
$this->assertContains('HTTP/1.1 999', HeaderStack::getHeaders());
}
/** @dataProvider headerProvider */
public function testSendsHeaders($header)
{
$this->response = $this->response
->withHeader("Content-length", ["2048"])
->withHeader("X-foo", ["bar", "baz"]);
->withHeader('Content-length', ['2048'])
->withHeader('X-foo', ['bar', 'baz']);
$transmitter = new Transmitter();
$transmitter->transmit($this->request, $this->response);
@ -70,15 +70,15 @@ class TransmitterTest extends TestCase
public function headerProvider()
{
return [
["Content-length: 2048"],
["X-foo: bar"],
["X-foo: baz"]
['Content-length: 2048'],
['X-foo: bar'],
['X-foo: baz']
];
}
public function testOutputsBody()
{
$content = "Hello, world!";
$content = 'Hello, world!';
$this->body->isReadable()->willReturn(true);
$this->body->__toString()->willReturn($content);
@ -96,7 +96,7 @@ class TransmitterTest extends TestCase
public function testOutputsBodyInChunks()
{
$content = "Hello, world!";
$content = 'Hello, world!';
$chunkSize = 3;
$position = 0;
@ -129,7 +129,7 @@ class TransmitterTest extends TestCase
public function testOutputsUnseekableStreamInChunks()
{
$content = "Hello, world!";
$content = 'Hello, world!';
$chunkSize = 3;
$position = 0;
@ -167,7 +167,7 @@ class TransmitterTest extends TestCase
{
$bodySize = 1024;
$this->body->isReadable()->willReturn(true);
$this->body->__toString()->willReturn("");
$this->body->__toString()->willReturn('');
$this->body->getSize()->willReturn($bodySize);
$transmitter = new Transmitter();
@ -182,10 +182,10 @@ class TransmitterTest extends TestCase
$streamSize = 1024;
$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->__toString()->willReturn("");
$this->body->__toString()->willReturn('');
$this->body->getSize()->willReturn($streamSize);
$transmitter = new Transmitter();
@ -199,30 +199,30 @@ class TransmitterTest extends TestCase
{
$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->__toString()->willReturn("");
$this->body->__toString()->willReturn('');
$this->body->getSize()->willReturn($bodySize);
$transmitter = new Transmitter();
$transmitter->setChunkSize(0);
$transmitter->transmit($this->request, $this->response);
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), "Content-length:");
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), 'Content-length:');
}
public function testDoesNotAddContentLengthHeaderWhenBodySizeIsNull()
{
$this->body->isReadable()->willReturn(true);
$this->body->__toString()->willReturn("");
$this->body->__toString()->willReturn('');
$this->body->getSize()->willReturn(null);
$transmitter = new Transmitter();
$transmitter->setChunkSize(0);
$transmitter->transmit($this->request, $this->response);
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), "Content-length:");
$this->assertArrayDoesNotContainValueWithPrefix(HeaderStack::getHeaders(), 'Content-length:');
}
private function assertArrayDoesNotContainValueWithPrefix($arr, $prefix)