diff --git a/CHANGELOG.md b/CHANGELOG.md index f3fcd1e..53bc8fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [4.1.0] - 2024-02-26 +### Added +* Support providing request options when calling `ApiTestCase::callShortUrl` + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [4.0.0] - 2024-02-20 ### Added * Add support for PHPUnit 11 diff --git a/src/ApiTest/ApiTestCase.php b/src/ApiTest/ApiTestCase.php index 1623d38..797f997 100644 --- a/src/ApiTest/ApiTestCase.php +++ b/src/ApiTest/ApiTestCase.php @@ -13,6 +13,8 @@ use Shlinkio\Shlink\TestUtils\Helper\CoverageHelper; use Shlinkio\Shlink\TestUtils\Helper\SeededTestCase; +use function is_array; +use function is_string; use function Shlinkio\Shlink\Json\json_decode; use function sprintf; use function str_starts_with; @@ -50,14 +52,21 @@ final protected function getJsonResponsePayload(ResponseInterface $resp): array return json_decode($body); } - final protected function callShortUrl(string $shortCode, ?string $userAgent = null): ResponseInterface + /** + * @param $userAgent - Calling this param with string is deprecated + * @todo Rename $userAgent to $options + */ + final protected function callShortUrl(string $shortCode, string|array|null $userAgent = null): ResponseInterface { - return $this->requestWithCoverageId(self::METHOD_GET, sprintf('/%s', $shortCode), [ - RequestOptions::ALLOW_REDIRECTS => false, - RequestOptions::HEADERS => [ + $options = is_array($userAgent) ? $userAgent : []; + $options[RequestOptions::ALLOW_REDIRECTS] = false; + if (is_string($userAgent)) { + $options[RequestOptions::HEADERS] = [ 'User-Agent' => $userAgent, - ], - ]); + ]; + } + + return $this->requestWithCoverageId(self::METHOD_GET, sprintf('/%s', $shortCode), $options); } private function requestWithCoverageId(string $method, string $uri, array $options): ResponseInterface