From e5d432f6d8058562f9a3488912d6e3c69dee3c80 Mon Sep 17 00:00:00 2001 From: Shudd3r Date: Sun, 7 Mar 2021 01:56:36 +0100 Subject: [PATCH 1/3] Updated code style to new dev tools requirements --- src/Cookie.php | 3 +++ src/Cookie/CookieSetup.php | 3 +++ src/Cookie/HeadersContextCookie.php | 5 +++++ src/Header.php | 5 +++++ src/Header/SetCookieHeader.php | 3 +++ src/ResponseHeaders.php | 11 +++++++++++ tests/HeadersContextCookieTest.php | 3 ++- 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Cookie.php b/src/Cookie.php index 4b82c70..bda337f 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -20,6 +20,9 @@ interface Cookie const NAME_EXTRA_CHARS = '!\#$%&\'*+\-.^_`|~'; const VALUE_EXTRA_CHARS = self::NAME_EXTRA_CHARS . '\/:=?\@()[\]{}<>'; + /** + * @return string + */ public function name(): string; /** diff --git a/src/Cookie/CookieSetup.php b/src/Cookie/CookieSetup.php index 0a45ff9..568d2c9 100644 --- a/src/Cookie/CookieSetup.php +++ b/src/Cookie/CookieSetup.php @@ -23,6 +23,9 @@ class CookieSetup private $responseHeaders; private $directives; + /** + * @param ResponseHeaders $responseHeaders + */ public function __construct(ResponseHeaders $responseHeaders) { $this->responseHeaders = $responseHeaders; diff --git a/src/Cookie/HeadersContextCookie.php b/src/Cookie/HeadersContextCookie.php index 0b8bf51..fb094eb 100644 --- a/src/Cookie/HeadersContextCookie.php +++ b/src/Cookie/HeadersContextCookie.php @@ -27,6 +27,11 @@ class HeadersContextCookie implements Cookie private $sent = false; + /** + * @param string $name + * @param array $directives + * @param ResponseHeaders $headers + */ public function __construct(string $name, array $directives, ResponseHeaders $headers) { $this->name = $this->validName($name); diff --git a/src/Header.php b/src/Header.php index 56902b9..9e430c3 100644 --- a/src/Header.php +++ b/src/Header.php @@ -16,5 +16,10 @@ interface Header { + /** + * @param MessageInterface $message + * + * @return MessageInterface New Message instance with modified headers + */ public function addToMessage(MessageInterface $message): MessageInterface; } diff --git a/src/Header/SetCookieHeader.php b/src/Header/SetCookieHeader.php index 92e6d60..f8c5852 100644 --- a/src/Header/SetCookieHeader.php +++ b/src/Header/SetCookieHeader.php @@ -19,6 +19,9 @@ class SetCookieHeader implements Header { private $header; + /** + * @param string $header + */ public function __construct(string $header) { $this->header = $header; diff --git a/src/ResponseHeaders.php b/src/ResponseHeaders.php index b710072..45c4769 100644 --- a/src/ResponseHeaders.php +++ b/src/ResponseHeaders.php @@ -39,11 +39,22 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface return $response; } + /** + * Adds Header that will modify server Response. + * + * @param Header $header + */ public function push(Header $header): void { $this->headers[] = $header; } + /** + * CookieSetup object can be used to configure Cookie header + * in server Response. + * + * @return CookieSetup + */ public function cookieSetup(): CookieSetup { return new CookieSetup($this); diff --git a/tests/HeadersContextCookieTest.php b/tests/HeadersContextCookieTest.php index c5261ae..84a2ad7 100644 --- a/tests/HeadersContextCookieTest.php +++ b/tests/HeadersContextCookieTest.php @@ -33,7 +33,8 @@ public function testInstantiation() public function testStandardSetup() { - $this->cookieSetup($context)->directives(['Expires' => $this->fixedDate(7200)]) + $this->cookieSetup($context) + ->directives(['Expires' => $this->fixedDate(7200)]) ->cookie('name') ->send('value'); From 6426b21b6ee3d101a5e76cba6910b090b8c83feb Mon Sep 17 00:00:00 2001 From: Shudd3r Date: Sun, 7 Mar 2021 02:10:37 +0100 Subject: [PATCH 2/3] Added strict types directive --- cs-fixer.php.dist | 2 +- src/Cookie/CookieSetup.php | 4 ++-- src/Cookie/Exception/CookieAlreadySentException.php | 2 +- src/Cookie/Exception/IllegalCharactersException.php | 2 +- src/Cookie/HeadersContextCookie.php | 2 +- src/Header/SetCookieHeader.php | 2 +- src/ResponseHeaders.php | 2 +- tests/Doubles/FakeHeader.php | 2 +- tests/Doubles/FakeRequestHandler.php | 2 +- tests/Doubles/FakeResponse.php | 2 +- tests/Doubles/FakeServerRequest.php | 2 +- tests/Doubles/FakeStream.php | 2 +- tests/Fixtures/time-functions.php | 2 +- tests/HeadersContextCookieTest.php | 6 +++--- tests/ResponseHeadersTest.php | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cs-fixer.php.dist b/cs-fixer.php.dist index e959b16..ee8a666 100644 --- a/cs-fixer.php.dist +++ b/cs-fixer.php.dist @@ -1,4 +1,4 @@ - null, 'Secure' => false, 'HttpOnly' => false, - 'SameSite' => false + 'SameSite' => null ]; foreach (HeadersContextCookie::DIRECTIVE_NAMES as $name) { diff --git a/src/Cookie/Exception/CookieAlreadySentException.php b/src/Cookie/Exception/CookieAlreadySentException.php index c21d1b2..909386d 100644 --- a/src/Cookie/Exception/CookieAlreadySentException.php +++ b/src/Cookie/Exception/CookieAlreadySentException.php @@ -1,4 +1,4 @@ - true, 'Domain' => 'example.com', 'Path' => '/directory/', - 'SameSite' => true + 'SameSite' => 'Lax' ]], ['fullCookie=foo; Domain=example.com; Path=/directory/; Expires=Tuesday, 01-May-2018 01:00:00 UTC; MaxAge=3600; Secure; HttpOnly; SameSite=Lax', [ 'name' => 'fullCookie', @@ -185,7 +185,7 @@ public function cookieData() 'HttpOnly' => true, 'Domain' => 'example.com', 'Path' => '/directory/', - 'SameSite' => true + 'SameSite' => 'Lax' ]] ]; } diff --git a/tests/ResponseHeadersTest.php b/tests/ResponseHeadersTest.php index eb1cb04..a9b070d 100644 --- a/tests/ResponseHeadersTest.php +++ b/tests/ResponseHeadersTest.php @@ -1,4 +1,4 @@ - Date: Sun, 7 Mar 2021 02:58:14 +0100 Subject: [PATCH 3/3] Added property & return type hints --- src/Cookie/CookieSetup.php | 8 +- src/Cookie/HeadersContextCookie.php | 8 +- src/Header/SetCookieHeader.php | 10 +- src/ResponseHeaders.php | 2 +- tests/Doubles/DummyServerRequest.php | 177 +++++++++++++++++++++++++++ tests/Doubles/DummyStream.php | 88 +++++++++++++ tests/Doubles/FakeHeader.php | 4 +- tests/Doubles/FakeRequestHandler.php | 9 +- tests/Doubles/FakeResponse.php | 61 ++++----- tests/Doubles/FakeServerRequest.php | 164 ------------------------- tests/Doubles/FakeStream.php | 98 --------------- tests/Fixtures/time-functions.php | 2 +- tests/HeadersContextCookieTest.php | 9 +- tests/ResponseHeadersTest.php | 15 +-- 14 files changed, 328 insertions(+), 327 deletions(-) create mode 100644 tests/Doubles/DummyServerRequest.php create mode 100644 tests/Doubles/DummyStream.php delete mode 100644 tests/Doubles/FakeServerRequest.php delete mode 100644 tests/Doubles/FakeStream.php diff --git a/src/Cookie/CookieSetup.php b/src/Cookie/CookieSetup.php index e05e7d4..8788fc2 100644 --- a/src/Cookie/CookieSetup.php +++ b/src/Cookie/CookieSetup.php @@ -20,8 +20,8 @@ class CookieSetup { private const FIVE_YEARS_IN_SEC = 157680000; - private $responseHeaders; - private $directives; + private ResponseHeaders $responseHeaders; + private array $directives; /** * @param ResponseHeaders $responseHeaders @@ -96,7 +96,7 @@ public function cookie(string $name): Cookie * * @return Cookie */ - public function permanentCookie($name): Cookie + public function permanentCookie(string $name): Cookie { $this->maxAge(self::FIVE_YEARS_IN_SEC); return $this->cookie($name); @@ -111,7 +111,7 @@ public function permanentCookie($name): Cookie * * @return Cookie */ - public function sessionCookie($name): Cookie + public function sessionCookie(string $name): Cookie { $this->httpOnly(); $this->sameSite('Lax'); diff --git a/src/Cookie/HeadersContextCookie.php b/src/Cookie/HeadersContextCookie.php index dc2b1fb..aed0d28 100644 --- a/src/Cookie/HeadersContextCookie.php +++ b/src/Cookie/HeadersContextCookie.php @@ -21,11 +21,11 @@ class HeadersContextCookie implements Cookie { const DIRECTIVE_NAMES = ['Domain', 'Path', 'Expires', 'MaxAge', 'Secure', 'HttpOnly', 'SameSite']; - private $name; - private $directives; - private $headers; + private string $name; + private array $directives; + private ResponseHeaders $headers; - private $sent = false; + private bool $sent = false; /** * @param string $name diff --git a/src/Header/SetCookieHeader.php b/src/Header/SetCookieHeader.php index e24a18d..45c4dcd 100644 --- a/src/Header/SetCookieHeader.php +++ b/src/Header/SetCookieHeader.php @@ -17,18 +17,18 @@ class SetCookieHeader implements Header { - private $header; + private string $headerValue; /** - * @param string $header + * @param string $headerValue */ - public function __construct(string $header) + public function __construct(string $headerValue) { - $this->header = $header; + $this->headerValue = $headerValue; } public function addToMessage(MessageInterface $message): MessageInterface { - return $message->withAddedHeader('Set-Cookie', $this->header); + return $message->withAddedHeader('Set-Cookie', $this->headerValue); } } diff --git a/src/ResponseHeaders.php b/src/ResponseHeaders.php index 8414e46..0a7e263 100644 --- a/src/ResponseHeaders.php +++ b/src/ResponseHeaders.php @@ -20,7 +20,7 @@ final class ResponseHeaders implements MiddlewareInterface { - private $headers = []; + private array $headers; /** * @param Header[] $headers diff --git a/tests/Doubles/DummyServerRequest.php b/tests/Doubles/DummyServerRequest.php new file mode 100644 index 0000000..010d487 --- /dev/null +++ b/tests/Doubles/DummyServerRequest.php @@ -0,0 +1,177 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Polymorphine\Headers\Tests\Doubles; + +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UriInterface; + + +class DummyServerRequest implements ServerRequestInterface +{ + public ?UriInterface $uri; + + public function __construct(UriInterface $uri = null) + { + $this->uri = $uri; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function getUri(): UriInterface + { + return $this->uri; + } + + public function getRequestTarget(): string + { + return 'foo?bar=baz'; + } + + public function getProtocolVersion(): string + { + return '1.1'; + } + + public function withProtocolVersion($version): self + { + return $this; + } + + public function getHeaders(): array + { + return []; + } + + public function hasHeader($name): bool + { + return false; + } + + public function getHeader($name): array + { + return []; + } + + public function getHeaderLine($name): string + { + return ''; + } + + public function withHeader($name, $value): self + { + return $this; + } + + public function withAddedHeader($name, $value): self + { + return $this; + } + + public function withoutHeader($name): self + { + return $this; + } + + public function getBody(): StreamInterface + { + return new DummyStream(); + } + + public function withBody(StreamInterface $body): self + { + return $this; + } + + public function withRequestTarget($requestTarget): self + { + return $this; + } + + public function withMethod($method): self + { + return $this; + } + + public function withUri(UriInterface $uri, $preserveHost = false): self + { + return $this; + } + + public function getServerParams(): array + { + return []; + } + + public function getCookieParams(): array + { + return []; + } + + public function withCookieParams(array $cookies): self + { + return $this; + } + + public function getQueryParams(): array + { + return []; + } + + public function withQueryParams(array $query): self + { + return $this; + } + + public function getUploadedFiles(): array + { + return []; + } + + public function withUploadedFiles(array $uploadedFiles): self + { + return $this; + } + + public function getParsedBody(): array + { + return []; + } + + public function withParsedBody($data): self + { + return $this; + } + + public function getAttributes(): array + { + return []; + } + + public function getAttribute($name, $default = null) + { + return $default; + } + + public function withAttribute($name, $value): self + { + return $this; + } + + public function withoutAttribute($name): self + { + return $this; + } +} diff --git a/tests/Doubles/DummyStream.php b/tests/Doubles/DummyStream.php new file mode 100644 index 0000000..f34c611 --- /dev/null +++ b/tests/Doubles/DummyStream.php @@ -0,0 +1,88 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Polymorphine\Headers\Tests\Doubles; + +use Psr\Http\Message\StreamInterface; + + +class DummyStream implements StreamInterface +{ + public function __toString(): string + { + return 'Hello world'; + } + + public function close(): void + { + } + + public function detach() + { + } + + public function getSize(): ?int + { + return 10; + } + + public function tell(): int + { + return 5; + } + + public function eof(): bool + { + return false; + } + + public function isSeekable(): bool + { + return true; + } + + public function seek($offset, $whence = SEEK_SET): void + { + } + + public function rewind(): void + { + } + + public function isWritable(): bool + { + return true; + } + + public function write($string): void + { + } + + public function isReadable(): bool + { + return true; + } + + public function read($length): string + { + return 'Hello'; + } + + public function getContents(): string + { + return ' World'; + } + + public function getMetadata($key = null): array + { + return []; + } +} diff --git a/tests/Doubles/FakeHeader.php b/tests/Doubles/FakeHeader.php index bf06db0..154b524 100644 --- a/tests/Doubles/FakeHeader.php +++ b/tests/Doubles/FakeHeader.php @@ -17,8 +17,8 @@ class FakeHeader implements Header { - private $name; - private $value; + private string $name; + private string $value; public function __construct(string $name, string $value) { diff --git a/tests/Doubles/FakeRequestHandler.php b/tests/Doubles/FakeRequestHandler.php index 6f7493c..56c6693 100644 --- a/tests/Doubles/FakeRequestHandler.php +++ b/tests/Doubles/FakeRequestHandler.php @@ -18,18 +18,15 @@ class FakeRequestHandler implements RequestHandlerInterface { - private $response; - private $sideEffect; + private ResponseInterface $response; - public function __construct(ResponseInterface $response, callable $sideEffect = null) + public function __construct(ResponseInterface $response) { - $this->response = $response; - $this->sideEffect = $sideEffect; + $this->response = $response; } public function handle(ServerRequestInterface $request): ResponseInterface { - if ($this->sideEffect) { ($this->sideEffect)(); } return $this->response; } } diff --git a/tests/Doubles/FakeResponse.php b/tests/Doubles/FakeResponse.php index e73d8d8..4ada7e8 100644 --- a/tests/Doubles/FakeResponse.php +++ b/tests/Doubles/FakeResponse.php @@ -11,93 +11,96 @@ namespace Polymorphine\Headers\Tests\Doubles; -use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; class FakeResponse implements ResponseInterface { - public $body; - public $headers = []; - public $protocol = '1.1'; - public $status = 200; - public $reason = 'OK'; - - /** - * @var ServerRequestInterface - */ - public $fromRequest; - - public function __construct($body = '') + public string $body; + public array $headers = []; + public string $protocol = '1.1'; + public int $status = 200; + public string $reason = 'OK'; + + public function __construct(string $body = '') { $this->body = $body; } - public function getProtocolVersion() + public function getProtocolVersion(): string { return $this->protocol; } - public function withProtocolVersion($version) + public function withProtocolVersion($version): self { + $this->protocol = $version; + return $this; } - public function getHeaders() + public function getHeaders(): array { return $this->headers; } - public function hasHeader($name) + public function hasHeader($name): bool { + return isset($this->headers[$name]); } - public function getHeader($name) + public function getHeader($name): array { return $this->headers[$name] ?? []; } - public function getHeaderLine($name) + public function getHeaderLine($name): string { + return implode(';', $this->headers[$name]); } - public function withHeader($name, $value) + public function withHeader($name, $value): self { $this->headers[$name] = [$value]; return $this; } - public function withAddedHeader($name, $value) + public function withAddedHeader($name, $value): self { $this->headers[$name][] = $value; return $this; } - public function withoutHeader($name) + public function withoutHeader($name): self { + unset($this->headers[$name]); + return $this; } - public function getBody() + public function getBody(): StreamInterface { - return is_string($this->body) ? new FakeStream($this->body) : $this->body; + return new DummyStream(); } - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): self { - $this->body = $body; + $this->body = (string) $body; return $this; } - public function getStatusCode() + public function getStatusCode(): ?int { return $this->status; } - public function withStatus($code, $reasonPhrase = '') + public function withStatus($code, $reasonPhrase = ''): self { + $this->status = $code; + $this->reason = $reasonPhrase; + return $this; } - public function getReasonPhrase() + public function getReasonPhrase(): string { return $this->reason; } diff --git a/tests/Doubles/FakeServerRequest.php b/tests/Doubles/FakeServerRequest.php deleted file mode 100644 index cb741e1..0000000 --- a/tests/Doubles/FakeServerRequest.php +++ /dev/null @@ -1,164 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Polymorphine\Headers\Tests\Doubles; - -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\StreamInterface; -use Psr\Http\Message\UriInterface; - - -class FakeServerRequest implements ServerRequestInterface -{ - public $uri; - public $method; - public $attr = []; - public $cookies = []; - public $parsed = []; - - public function __construct(string $method = 'GET', UriInterface $uri = null) - { - $this->method = $method; - $this->uri = $uri; - } - - public function getMethod() - { - return $this->method ?: 'GET'; - } - - public function getUri() - { - return $this->uri; - } - - public function getRequestTarget() - { - $query = $this->getUri()->getquery(); - $path = $this->getUri()->getPath(); - - return $query ? $path . '?' . $query : $path; - } - - public function getProtocolVersion() - { - } - - public function withProtocolVersion($version) - { - } - - public function getHeaders() - { - } - - public function hasHeader($name) - { - } - - public function getHeader($name) - { - } - - public function getHeaderLine($name) - { - } - - public function withHeader($name, $value) - { - } - - public function withAddedHeader($name, $value) - { - } - - public function withoutHeader($name) - { - } - - public function getBody() - { - } - - public function withBody(StreamInterface $body) - { - } - - public function withRequestTarget($requestTarget) - { - } - - public function withMethod($method) - { - } - - public function withUri(UriInterface $uri, $preserveHost = false) - { - } - - public function getServerParams() - { - } - - public function getCookieParams() - { - return $this->cookies; - } - - public function withCookieParams(array $cookies) - { - } - - public function getQueryParams() - { - } - - public function withQueryParams(array $query) - { - } - - public function getUploadedFiles() - { - } - - public function withUploadedFiles(array $uploadedFiles) - { - } - - public function getParsedBody() - { - return $this->parsed; - } - - public function withParsedBody($data) - { - } - - public function getAttributes() - { - return $this->attr; - } - - public function getAttribute($name, $default = null) - { - return $this->attr[$name] ?? $default; - } - - public function withAttribute($name, $value) - { - $this->attr[$name] = $value; - return $this; - } - - public function withoutAttribute($name) - { - } -} diff --git a/tests/Doubles/FakeStream.php b/tests/Doubles/FakeStream.php deleted file mode 100644 index 2a505a6..0000000 --- a/tests/Doubles/FakeStream.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Polymorphine\Headers\Tests\Doubles; - -use Psr\Http\Message\StreamInterface; - - -class FakeStream implements StreamInterface -{ - public $seekable = true; - - private $body; - private $stream; - - public function __construct(string $body = '') - { - $this->body = $body; - $this->stream = $body; - } - - public function __toString() - { - return $this->body; - } - - public function close() - { - } - - public function detach() - { - } - - public function getSize() - { - return strlen($this->stream); - } - - public function tell() - { - } - - public function eof() - { - return empty($this->stream); - } - - public function isSeekable() - { - return $this->seekable; - } - - public function seek($offset, $whence = SEEK_SET) - { - } - - public function rewind() - { - $this->stream = $this->body; - } - - public function isWritable() - { - } - - public function write($string) - { - } - - public function isReadable() - { - return true; - } - - public function read($length) - { - $send = substr($this->stream, 0, $length); - $this->stream = substr($this->stream, $length); - return $send; - } - - public function getContents() - { - } - - public function getMetadata($key = null) - { - } -} diff --git a/tests/Fixtures/time-functions.php b/tests/Fixtures/time-functions.php index c539d49..06754d4 100644 --- a/tests/Fixtures/time-functions.php +++ b/tests/Fixtures/time-functions.php @@ -11,7 +11,7 @@ namespace Polymorphine\Headers\Cookie; -function time() +function time(): int { return 1525132800; } diff --git a/tests/HeadersContextCookieTest.php b/tests/HeadersContextCookieTest.php index 30805de..238da51 100644 --- a/tests/HeadersContextCookieTest.php +++ b/tests/HeadersContextCookieTest.php @@ -34,7 +34,7 @@ public function testInstantiation() public function testStandardSetup() { $this->cookieSetup($context) - ->directives(['Expires' => $this->fixedDate(7200)]) + ->expires($this->fixedDate(7200)) ->cookie('name') ->send('value'); @@ -160,7 +160,7 @@ public function testGivenCookieWasSent_SendCookie_ThrowsException() $cookie->send('value'); } - public function cookieData() + public function cookieData(): array { return [ ['myCookie=; Path=/; Expires=Thursday, 01-Jan-1970 00:00:00 UTC; MaxAge=-1525132800', [ @@ -202,7 +202,8 @@ public function invalidValues(): array private function fixedDate(int $secondsFromNow = 0): DateTime { - return (new DateTime())->setTimestamp(\Polymorphine\Headers\Cookie\time() + $secondsFromNow); + $date = new DateTime(); + return $date->setTimestamp(\Polymorphine\Headers\Cookie\time() + $secondsFromNow); } private function cookieSetup(&$context = null): CookieSetup @@ -213,7 +214,7 @@ private function cookieSetup(&$context = null): CookieSetup private function responseHeader(ResponseHeaders $context): array { - $request = new Doubles\FakeServerRequest(); + $request = new Doubles\DummyServerRequest(); $handler = new Doubles\FakeRequestHandler(new Doubles\FakeResponse()); return $context->process($request, $handler)->getHeader('Set-Cookie'); diff --git a/tests/ResponseHeadersTest.php b/tests/ResponseHeadersTest.php index a9b070d..8c3b633 100644 --- a/tests/ResponseHeadersTest.php +++ b/tests/ResponseHeadersTest.php @@ -12,13 +12,9 @@ namespace Polymorphine\Headers\Tests; use PHPUnit\Framework\TestCase; -use Polymorphine\Headers\Cookie\CookieSetup; use Polymorphine\Headers\ResponseHeaders; +use Polymorphine\Headers\Cookie\CookieSetup; use Polymorphine\Headers\Header; -use Polymorphine\Headers\Tests\Doubles\FakeHeader; -use Polymorphine\Headers\Tests\Doubles\FakeRequestHandler; -use Polymorphine\Headers\Tests\Doubles\FakeServerRequest; -use Polymorphine\Headers\Tests\Doubles\FakeResponse; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Message\ResponseInterface; @@ -32,8 +28,8 @@ public function testInstantiation() public function testAddHeaders() { - $headers = $this->middleware(new FakeHeader('Set-Cookie', 'default=value')); - $headers->push(new FakeHeader('Set-Cookie', 'name=value')); + $headers = $this->middleware(new Doubles\FakeHeader('Set-Cookie', 'default=value')); + $headers->push(new Doubles\FakeHeader('Set-Cookie', 'name=value')); $this->assertSame(['Set-Cookie' => ['default=value', 'name=value']], $this->response($headers)->getHeaders()); } @@ -42,13 +38,14 @@ public function testCookieSetup() $this->assertInstanceOf(CookieSetup::class, $this->middleware()->cookieSetup()); } - private function middleware(Header ...$headers) + private function middleware(Header ...$headers): ResponseHeaders { return new ResponseHeaders(...$headers); } private function response(MiddlewareInterface $headers): ResponseInterface { - return $headers->process(new FakeServerRequest(), new FakeRequestHandler(new FakeResponse())); + $handler = new Doubles\FakeRequestHandler(new Doubles\FakeResponse()); + return $headers->process(new Doubles\DummyServerRequest(), $handler); } }