Skip to content

Commit

Permalink
Allow passing request options when calling ApiTestCase::callShortUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Feb 26, 2024
1 parent 76986c3 commit 4bbae2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions src/ApiTest/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bbae2a

Please sign in to comment.