diff --git a/README.md b/README.md index b23f040..e6201e4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This PHP 7.1 library provides a collection of [PSR-7](https://www.php-fig.org/ps * [`HtmlResponse`](src/HtmlResponse.php) * [`HttpProxyResponse`](src/HttpProxyResponse.php) * [`JsonResponse`](src/JsonResponse.php) +* [`LocalFileResponse`](src/LocalFileResponse.php) * [`NotFoundResponse`](src/NotFoundResponse.php) * [`RedirectResponse`](src/RedirectResponse.php) * [`StreamResponse`](src/StreamResponse.php) diff --git a/composer.json b/composer.json index 3e9cf21..fbc6d92 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "codeinc/psr7-responses", - "version": "2.0.2", + "version": "2.1.0", "description": "A collection of PSR-7 responses", "homepage": "https://github.com/CodeIncHQ/Psr7Responses", "type": "library", diff --git a/src/CharsetResponseInterface.php b/src/CharsetResponseInterface.php deleted file mode 100644 index 7853750..0000000 --- a/src/CharsetResponseInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - -// Date: 08/10/2018 -// Project: Psr7Responses -// -declare(strict_types=1); -namespace CodeInc\Psr7Responses; - -/** - * Interface CharsetResponseInterface - * - * @package CodeInc\Psr7Responses - * @author Joan Fabrégat - */ -interface CharsetResponseInterface -{ - /** - * Returns the response's charset. - * - * @return string - */ - public function getCharset():string; -} \ No newline at end of file diff --git a/src/EmptyResponse.php b/src/EmptyResponse.php index 84260b7..4b2867b 100644 --- a/src/EmptyResponse.php +++ b/src/EmptyResponse.php @@ -39,7 +39,7 @@ class EmptyResponse extends Response * @param array $headers * @param string $version */ - public function __construct(int $code = 404, string $reasonPhrase = '', + public function __construct(int $code = 200, string $reasonPhrase = '', array $headers = [], string $version = '1.1') { parent::__construct($code, $headers, '', $version, $reasonPhrase); diff --git a/src/ErrorResponse.php b/src/ErrorResponse.php index d9b0f56..dbedaab 100644 --- a/src/ErrorResponse.php +++ b/src/ErrorResponse.php @@ -48,20 +48,18 @@ class ErrorResponse extends HtmlResponse * @param \Throwable $error * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version * @throws \ReflectionException */ public function __construct(\Throwable $error, int $code = 200, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { $this->error = $error; parent::__construct( (new HtmlErrorRenderer($error))->get(), $code, $reasonPhrase, - $charset, $headers, $version ); diff --git a/src/FileResponse.php b/src/FileResponse.php index 3364cbc..59f4b33 100644 --- a/src/FileResponse.php +++ b/src/FileResponse.php @@ -3,86 +3,69 @@ // +---------------------------------------------------------------------+ // | CODE INC. SOURCE CODE | // +---------------------------------------------------------------------+ -// | Copyright (c) 2017 - Code Inc. SAS - All Rights Reserved. | +// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | // | Visit https://www.codeinc.fr for more information about licensing. | // +---------------------------------------------------------------------+ // | NOTICE: All information contained herein is, and remains the | // | property of Code Inc. SAS. The intellectual and technical concepts | // | contained herein are proprietary to Code Inc. SAS are protected by | // | trade secret or copyright law. Dissemination of this information or | -// | reproduction of this material is strictly forbidden unless prior | +// | reproduction of this material is strictly forbidden unless prior | // | written permission is obtained from Code Inc. SAS. | // +---------------------------------------------------------------------+ // // Author: Joan Fabrégat -// Date: 23/02/2018 -// Time: 19:15 +// Date: 08/10/2018 // Project: Psr7Responses // -declare(strict_types = 1); +declare(strict_types=1); namespace CodeInc\Psr7Responses; use CodeInc\MediaTypes\MediaTypes; use function GuzzleHttp\Psr7\stream_for; -use Psr\Http\Message\StreamInterface; /** * Class FileResponse * - * @see FileResponseTest * @package CodeInc\Psr7Responses * @author Joan Fabrégat - * @license MIT - * @link https://github.com/CodeIncHQ/Psr7Responses - * @version 2 */ class FileResponse extends StreamResponse { /** * FileResponse constructor. * - * @param string|resource|StreamInterface $file * @param string $fileName + * @param $data * @param int $code * @param string $reasonPhrase * @param null|string $contentType + * @param int|null $contentLength * @param bool $asAttachment * @param array $headers * @param string $version * @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException */ - public function __construct($file, string $fileName, int $code = 200, string $reasonPhrase = '', - ?string $contentType = null, bool $asAttachment = true, array $headers = [], string $version = '1.1') - { - if (is_string($file)) { - if (!is_file($file)) { - throw new ResponseException( - sprintf("The path \"%s\" is not a file or does not exist", $file), - $this - ); - } - if (($handler = fopen($file, "r")) === false) { - throw new ResponseException( - sprintf("Unable to open the file \"%s\" for reading", $file), - $this - ); - } - $stream = stream_for($handler); + public function __construct(string $fileName, $data, int $code = 200, string $reasonPhrase = '', + ?string $contentType = null, ?int $contentLength = null, bool $asAttachment = true, + array $headers = [], string $version = '1.1') + { + $stream = stream_for($data); + + // adding headers + if (!isset($headers['Content-Type']) && $contentType) { + $headers['Content-Type'] = $contentType + ?? MediaTypes::getFilenameMediaType($fileName) + ?? 'application/octet-stream'; + } + if (!isset($headers['Content-Disposition'])) { + $headers['Content-Disposition'] = sprintf('%s; filename="%s"', + ($asAttachment ? 'attachment' : 'inline'), $fileName); } - else { - $stream = stream_for($file); + if (!isset($headers['Content-Length']) && ($contentLength !== null || ($contentLength = $stream->getSize()) !== null)) { + $headers['Content-Length'] = $contentLength; } - parent::__construct( - $stream, - $code, - $reasonPhrase, - $contentType ?? MediaTypes::getFilenameMediaType($fileName, 'application/octet-stream'), - null, - $fileName, - $asAttachment, - $headers, - $version - ); - } + parent::__construct($stream, $code, $reasonPhrase, $headers, $version); + } } \ No newline at end of file diff --git a/src/ForbiddenResponse.php b/src/ForbiddenResponse.php index d3eac1a..98c664d 100644 --- a/src/ForbiddenResponse.php +++ b/src/ForbiddenResponse.php @@ -40,13 +40,18 @@ class ForbiddenResponse extends HtmlResponse * @param string $html * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $html = '', int $code = 403, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { - parent::__construct($html, $code, $reasonPhrase, $charset, $headers, $version); + parent::__construct( + $html, + $code, + $reasonPhrase, + $headers, + $version + ); } } \ No newline at end of file diff --git a/src/HtmlResponse.php b/src/HtmlResponse.php index e71a02f..a711a06 100644 --- a/src/HtmlResponse.php +++ b/src/HtmlResponse.php @@ -33,17 +33,16 @@ * @link https://github.com/CodeIncHQ/Psr7Responses * @version 2 */ -class HtmlResponse extends Response implements CharsetResponseInterface +class HtmlResponse extends Response { - /** - * @var string - */ - private $html; + public const DEFAULT_HEADERS = [ + 'Content-Type' => 'text/html; charset=utf-8' + ]; /** * @var string */ - private $charset; + private $html; /** * HtmlResponse constructor. @@ -51,17 +50,20 @@ class HtmlResponse extends Response implements CharsetResponseInterface * @param string $html * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $html, int $code = 200, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { - $headers['Content-Type'] = sprintf('text/html; charset=%s', $charset); - $this->html = $html; - $this->charset = $charset; - parent::__construct($code, $headers, $html, $version, $reasonPhrase); + $this->html = $html; + parent::__construct( + $code, + $headers, + $html, + $version, + $reasonPhrase + ); } /** @@ -73,13 +75,4 @@ public function getHtml():string { return $this->html; } - - /** - * @inheritdoc - * @return string - */ - public function getCharset():string - { - return $this->charset; - } } \ No newline at end of file diff --git a/src/HttpProxyResponse.php b/src/HttpProxyResponse.php index b1be307..6577071 100644 --- a/src/HttpProxyResponse.php +++ b/src/HttpProxyResponse.php @@ -52,16 +52,16 @@ class HttpProxyResponse extends Response /** * @var string[] */ - private $acceptableResponseHeaders = [ - 'content-type', - 'content-length', - 'content-disposition', - 'date', - 'last-modified', - 'etag', - 'pragma', - 'expires', - 'cache-control' + private $acceptableProxyHeaders = [ + 'Content-Type', + 'Content-Length', + 'Content-Disposition', + 'Date', + 'Last-Modified', + 'Etag', + 'Pragma', + 'Expires', + 'Cache-Control' ]; /** @@ -75,10 +75,7 @@ class HttpProxyResponse extends Response public function __construct(string $remoteUrl, array $headers = [], string $version = '1.1') { if (!filter_var($remoteUrl, FILTER_VALIDATE_URL)) { - throw new ResponseException( - sprintf("%s is not a valid URL", $remoteUrl), - $this - ); + throw new \RuntimeException(sprintf("%s is not a valid URL", $remoteUrl)); } $this->remoteUrl = $remoteUrl; @@ -115,7 +112,7 @@ public function getResponseHeaders():array { $headers = []; foreach ($this->getResponse()->getHeaders() as $header => $values) { - if (in_array(strtolower($header), $this->acceptableResponseHeaders)) { + if (preg_grep('/^'.preg_quote($header, '$/').'/ui', $this->acceptableProxyHeaders)) { $headers[$header] = $values; } } @@ -125,17 +122,17 @@ public function getResponseHeaders():array /** * @return string[] */ - public function getAcceptableResponseHeaders():array + public function getAcceptableProxyHeaders():array { - return $this->acceptableResponseHeaders; + return $this->acceptableProxyHeaders; } /** - * @param string[] $acceptableResponseHeaders + * @param string[] $acceptableProxyHeaders */ - public function setAcceptableResponseHeaders(array $acceptableResponseHeaders):void + public function setAcceptableProxyHeaders(array $acceptableProxyHeaders):void { - $this->acceptableResponseHeaders = $acceptableResponseHeaders; + $this->acceptableProxyHeaders = $acceptableProxyHeaders; } /** diff --git a/src/JsonResponse.php b/src/JsonResponse.php index 567a8f0..766746c 100644 --- a/src/JsonResponse.php +++ b/src/JsonResponse.php @@ -33,17 +33,16 @@ * @link https://github.com/CodeIncHQ/Psr7Responses * @version 2 */ -class JsonResponse extends Response implements CharsetResponseInterface +class JsonResponse extends Response { - /** - * @var string - */ - private $json; + public const DEFAULT_HEADERS = [ + 'Content-Type' => 'application/json; charset=utf-8' + ]; /** * @var string */ - private $charset; + private $json; /** * TextResponse constructor. @@ -51,16 +50,13 @@ class JsonResponse extends Response implements CharsetResponseInterface * @param string $json * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $json, int $code = 200, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { $this->json = $json; - $this->charset = $charset; - $headers['Content-Type'] = sprintf('application/json; charset=%s', $charset); parent::__construct($code, $headers, $json, $version, $reasonPhrase); } @@ -79,24 +75,12 @@ public function getJson():string * * @uses json_decode() * @return array - * @throws ResponseException */ public function getDecodedJson():array { if (!($array = json_decode($this->json, true))) { - throw new ResponseException("Unable to decode the response's JSON", $this); + throw new \RuntimeException("Unable to decode the response's JSON"); } return json_decode($this->json, true); } - - /** - * @inheritdoc - * @return string - */ - public function getCharset():string - { - return $this->charset; - } - - } \ No newline at end of file diff --git a/src/LocalFileResponse.php b/src/LocalFileResponse.php index 5dc48c5..347d996 100644 --- a/src/LocalFileResponse.php +++ b/src/LocalFileResponse.php @@ -3,65 +3,73 @@ // +---------------------------------------------------------------------+ // | CODE INC. SOURCE CODE | // +---------------------------------------------------------------------+ -// | Copyright (c) 2017 - Code Inc. SAS - All Rights Reserved. | +// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | // | Visit https://www.codeinc.fr for more information about licensing. | // +---------------------------------------------------------------------+ // | NOTICE: All information contained herein is, and remains the | // | property of Code Inc. SAS. The intellectual and technical concepts | // | contained herein are proprietary to Code Inc. SAS are protected by | // | trade secret or copyright law. Dissemination of this information or | -// | reproduction of this material is strictly forbidden unless prior | +// | reproduction of this material is strictly forbidden unless prior | // | written permission is obtained from Code Inc. SAS. | // +---------------------------------------------------------------------+ // // Author: Joan Fabrégat -// Date: 23/02/2018 -// Time: 19:15 +// Date: 08/10/2018 // Project: Psr7Responses // -declare(strict_types = 1); +declare(strict_types=1); namespace CodeInc\Psr7Responses; -use CodeInc\Psr7Responses\Tests\LocalFileResponseTest; /** * Class LocalFileResponse * - * @see LocalFileResponseTest * @package CodeInc\Psr7Responses * @author Joan Fabrégat - * @license MIT - * @link https://github.com/CodeIncHQ/Psr7Responses - * @version 2 */ class LocalFileResponse extends FileResponse { /** * LocalFileResponse constructor. * - * @param string $filePath Local file path + * @param string $filePath * @param int $code * @param string $reasonPhrase - * @param null|string $fileName File's name (determined from the local file path if not specified) - * @param null|string $contentType File's content type (determined from the file's name if not specified) - * @param bool $asAttachment Defines if the file should be sent as an attachment + * @param null|string $fileName + * @param null|string $contentType + * @param int|null $contentLength + * @param bool $asAttachment * @param array $headers * @param string $version * @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException */ - public function __construct(string $filePath, int $code = 200, string $reasonPhrase = '', - ?string $fileName = null, ?string $contentType = null, bool $asAttachment = true, + public function __construct(string $filePath, int $code = 200, string $reasonPhrase = '', ?string $fileName = null, + ?string $contentType = null, ?int $contentLength = null, bool $asAttachment = true, array $headers = [], string $version = '1.1') - { - parent::__construct( - $filePath, - $fileName ?? basename($filePath), + { + // opening the local file + if (!is_file($filePath)) { + throw new \RuntimeException( + sprintf("The path \"%s\" is not a file or does not exist", $filePath) + ); + } + if (($handler = fopen($filePath, "r")) === false) { + throw new \RuntimeException( + sprintf("Unable to open the file \"%s\" for reading", $filePath) + ); + } + + parent::__construct( + $fileName ?? basename($filePath), + $handler, $code, $reasonPhrase, - $contentType, - $asAttachment, + $contentType, + $contentLength ?? filesize($filePath), + $asAttachment, $headers, $version - ); - } + ); + } } \ No newline at end of file diff --git a/src/NotFoundResponse.php b/src/NotFoundResponse.php index b20f3f0..ea9f6ad 100644 --- a/src/NotFoundResponse.php +++ b/src/NotFoundResponse.php @@ -40,18 +40,16 @@ class NotFoundResponse extends HtmlResponse * @param string $html * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $html = '', int $code = 404, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { parent::__construct( $html ?? '', $code, $reasonPhrase, - $charset, $headers, $version ); diff --git a/src/ResponseException.php b/src/ResponseException.php deleted file mode 100644 index 8654c29..0000000 --- a/src/ResponseException.php +++ /dev/null @@ -1,64 +0,0 @@ - -// Date: 23/02/2018 -// Time: 17:52 -// Project: Psr7Responses -// -declare(strict_types = 1); -namespace CodeInc\Psr7Responses; -use Psr\Http\Message\ResponseInterface; - - -/** - * Class ResponseException - * - * @package CodeInc\Psr7Responses - * @author Joan Fabrégat - * @license MIT - * @link https://github.com/CodeIncHQ/Psr7Responses - */ -class ResponseException extends \RuntimeException -{ - /** - * @var ResponseInterface - */ - private $response; - - /** - * ResponseException constructor. - * - * @param string $message - * @param ResponseInterface $response - * @param int|null $code - * @param null|\Throwable $previous - */ - public function __construct(string $message, ResponseInterface $response, ?int $code = null, - ?\Throwable $previous = null) - { - $this->response = $response; - parent::__construct($message, $code ?? 0, $previous); - } - - /** - * @return ResponseInterface - */ - public function getResponse():ResponseInterface - { - return $this->response; - } -} \ No newline at end of file diff --git a/src/StreamResponse.php b/src/StreamResponse.php index adb8a7d..b3cec54 100644 --- a/src/StreamResponse.php +++ b/src/StreamResponse.php @@ -42,63 +42,20 @@ class StreamResponse extends Response */ private $stream; - /** - * @var null|string - */ - private $contentType; - - /** - * @var int|null - */ - private $contentLength; - - /** - * @var null|string - */ - private $fileName; - - /** - * @var bool - */ - private $asAttachment; - /** * StreamResponse constructor. * - * @uses stream_for() - * @param resource|string|null|int|float|bool|StreamInterface|callable $dataSource + * @param StreamInterface $stream * @param int $code * @param string $reasonPhrase - * @param null|string $contentType - * @param int|null $contentLength - * @param null|string $fileName - * @param bool $asAttachment * @param array $headers * @param string $version */ - public function __construct($dataSource, int $code = 200, string $reasonPhrase = '', - ?string $contentType = null, ?int $contentLength = null, ?string $fileName = null, - bool $asAttachment = false, array $headers = [], string $version = '1.1') + public function __construct(StreamInterface $stream, int $code = 200, string $reasonPhrase = '', + array $headers = [], string $version = '1.1') { - $this->stream = stream_for($dataSource); - $this->contentType = $contentType; - $this->contentLength = $contentLength; - $this->fileName = $fileName; - $this->asAttachment = $asAttachment; - - // adding headers - if ($contentType) { - $headers["Content-Type"] = $contentType; - } - $headers["Content-Disposition"] = $asAttachment ? "attachment" : "inline"; - if ($fileName) { - $headers["Content-Disposition"] .= sprintf("; filename=\"%s\"", $fileName); - } - if ($contentLength !== null || ($contentLength = $this->stream->getSize()) !== null) { - $headers["Content-Length"] = $contentLength; - } - - parent::__construct($code, $headers, $this->stream, $version, $reasonPhrase); + $this->stream = $stream; + parent::__construct($code, $headers, $stream, $version, $reasonPhrase); } /** @@ -110,44 +67,4 @@ public function getStream():StreamInterface { return $this->stream; } - - /** - * Returns the response's content type or NULL if not set. - * - * @return null|string - */ - public function getContentType():?string - { - return $this->contentType; - } - - /** - * Returns the response's content's length or NULL if not set. - * - * @return int|null - */ - public function getContentLength():?int - { - return $this->contentLength; - } - - /** - * Returns the response's filename or NULL if not set. - * - * @return null|string - */ - public function getFileName():?string - { - return $this->fileName; - } - - /** - * Verify if the response must be treated as an attachment. - * - * @return bool - */ - public function isAsAttachment():bool - { - return $this->asAttachment; - } } \ No newline at end of file diff --git a/src/TextResponse.php b/src/TextResponse.php index d31a9cd..ad3c922 100644 --- a/src/TextResponse.php +++ b/src/TextResponse.php @@ -33,17 +33,16 @@ * @link https://github.com/CodeIncHQ/Psr7Responses * @version 2 */ -class TextResponse extends Response implements CharsetResponseInterface +class TextResponse extends Response { - /** - * @var string - */ - private $text; + public const DEFAULT_HEADERS = [ + 'Content-Type' => 'text/plain; charset=utf-8' + ]; /** * @var string */ - private $charset; + private $text; /** * TextResponse constructor. @@ -51,15 +50,12 @@ class TextResponse extends Response implements CharsetResponseInterface * @param string $text * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $text, int $code = 200, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { - $this->charset = $charset; - $headers['Content-Type'] = sprintf('text/plain; charset=%s', $charset); parent::__construct($code, $headers, $text, $version, $reasonPhrase); } @@ -70,13 +66,4 @@ public function getText():string { return $this->text; } - - /** - * @inheritdoc - * @return string - */ - public function getCharset():string - { - return $this->charset; - } } \ No newline at end of file diff --git a/src/UnauthorizedResponse.php b/src/UnauthorizedResponse.php index 84b1a5d..cc5711b 100644 --- a/src/UnauthorizedResponse.php +++ b/src/UnauthorizedResponse.php @@ -39,13 +39,12 @@ class UnauthorizedResponse extends HtmlResponse * @param string $html * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $html = '', int $code = 401, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { - parent::__construct($html, $code, $reasonPhrase, $charset, $headers, $version); + parent::__construct($html, $code, $reasonPhrase, $headers, $version); } } \ No newline at end of file diff --git a/src/XmlResponse.php b/src/XmlResponse.php index 7486fb1..1634cc2 100644 --- a/src/XmlResponse.php +++ b/src/XmlResponse.php @@ -33,17 +33,16 @@ * @link https://github.com/CodeIncHQ/Psr7Responses * @version 2 */ -class XmlResponse extends Response implements CharsetResponseInterface +class XmlResponse extends Response { - /** - * @var string - */ - private $xml; + public const DEFAULT_HEADERS = [ + 'Content-Type' => 'application/xml; charset=utf-8' + ]; /** * @var string */ - private $charset; + private $xml; /** * TextResponse constructor. @@ -51,16 +50,13 @@ class XmlResponse extends Response implements CharsetResponseInterface * @param string $xml * @param int $code * @param string $reasonPhrase - * @param string $charset * @param array $headers * @param string $version */ public function __construct(string $xml, int $code = 200, string $reasonPhrase = '', - string $charset = 'utf-8', array $headers = [], string $version = '1.1') + array $headers = self::DEFAULT_HEADERS, string $version = '1.1') { $this->xml = $xml; - $this->charset = $charset; - $headers['Content-Type'] = sprintf('application/xml; charset=%s', $charset); parent::__construct($code, $headers, $xml, $version, $reasonPhrase); } @@ -71,13 +67,4 @@ public function getXml():string { return $this->xml; } - - /** - * @inheritdoc - * @return string - */ - public function getCharset():string - { - return $this->charset; - } } \ No newline at end of file diff --git a/tests/HttpProxyResponseTest.php b/tests/HttpProxyResponseTest.php index ad451ee..95461c0 100644 --- a/tests/HttpProxyResponseTest.php +++ b/tests/HttpProxyResponseTest.php @@ -39,7 +39,7 @@ final class HttpProxyResponseTest extends AbstractResponseTestCase private const TEST_IMG_URL = 'https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg'; /** - * @throws \CodeInc\Psr7Responses\ResponseException + * @throws \GuzzleHttp\Exception\GuzzleException */ public function testTxtResponse():void { @@ -48,8 +48,9 @@ public function testTxtResponse():void self::assertResponseStatusCode(200, $response); self::assertResponseHasBody($response); } + /** - * @throws \CodeInc\Psr7Responses\ResponseException + * @throws \GuzzleHttp\Exception\GuzzleException */ public function testImgResponse():void { diff --git a/tests/LocalFileResponseTest.php b/tests/LocalFileResponseTest.php index 8ddfe64..90d92c5 100644 --- a/tests/LocalFileResponseTest.php +++ b/tests/LocalFileResponseTest.php @@ -21,8 +21,7 @@ // declare(strict_types=1); namespace CodeInc\Psr7Responses\Tests; -use CodeInc\Psr7Responses\FileResponse; -use CodeInc\Psr7Responses\LocalFileResponse; +use CodeInc\Psr7Responses\StreamResponse; /** @@ -38,11 +37,10 @@ class LocalFileResponseTest extends AbstractResponseTestCase { /** * @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException - * @throws \CodeInc\Psr7Responses\ResponseException */ public function test():void { - $response = new LocalFileResponse(__DIR__.'/Assets/file.txt'); + $response = StreamResponse::localFileFactory(__DIR__.'/Assets/file.txt'); self::assertIsResponse($response); self::assertResponseStatusCode(200, $response); self::assertResponseHasBody($response);