Skip to content

Commit

Permalink
Merge pull request #46 from ember-nexus/feature/head-assertions
Browse files Browse the repository at this point in the history
Add assertions to test identical headers in HEAD and GET requests aut…
  • Loading branch information
Syndesi authored Sep 2, 2023
2 parents d244564 + ae65597 commit 3e0572b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Changed
- Hotfix.
### Added
- Add assertions to test identical headers in HEAD and GET requests automatically.

## 0.0.25 - 2023-08-31
### Changed
Expand Down
17 changes: 16 additions & 1 deletion tests/FeatureTests/BaseRequestTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@

abstract class BaseRequestTestCase extends TestCase
{
private const IGNORED_HEAD_HEADERS = ['X-Debug-Token', 'X-Debug-Token-Link', 'Date'];

public function runGetRequest(string $uri, string $token): ResponseInterface
{
return $this->runRequest('GET', $uri, $token);
$headRequest = $this->runRequest('HEAD', $uri, $token);
$getRequest = $this->runRequest('GET', $uri, $token);

$headHeaders = $headRequest->getHeaders();
$getHeaders = $getRequest->getHeaders();
foreach ($headHeaders as $key => $value) {
$this->assertArrayHasKey($key, $getHeaders);
if (in_array($key, self::IGNORED_HEAD_HEADERS)) {
continue;
}
$this->assertSame($value, $getHeaders[$key]);
}

return $getRequest;
}

public function runPostRequest(string $uri, string $token, array $data): ResponseInterface
Expand Down

0 comments on commit 3e0572b

Please sign in to comment.