Skip to content

Commit

Permalink
Merge pull request #8 from niels-nijens/http-client-contracts
Browse files Browse the repository at this point in the history
Add version 2 of the symfony/http-client-contracts dependency as possible requirement
  • Loading branch information
niels-nijens authored Dec 8, 2020
2 parents a6fd56a + 190c19a commit 75a1d3c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^7.1.3",
"symfony/cache": "^4.2",
"symfony/http-client-contracts": "^1.1"
"symfony/http-client-contracts": "^1.1 || ^2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
Expand Down
86 changes: 63 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 29 additions & 22 deletions tests/AuthZeroAuthenticatingHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public function testRequestWithAuthZeroAuthenticationSuccessful()
$response = $this->httpClient->request('GET', 'https://superbrave.nl/api');

$this->assertSame(
array(
'authorization' => array(
sprintf('Bearer %s', $accessToken),
),
),
$response->getRequestOptions()['headers']
[
'accept' => ['Accept: */*'],
'authorization' => [
sprintf('Authorization: Bearer %s', $accessToken),
],
],
$response->getRequestOptions()['normalized_headers']
);
}

Expand All @@ -106,24 +107,26 @@ public function testRequestReadsAccessTokenFromCache()
$response = $this->httpClient->request('GET', 'https://superbrave.nl/api');

$this->assertSame(
array(
'authorization' => array(
sprintf('Bearer %s', $accessToken),
),
),
$response->getRequestOptions()['headers']
[
'accept' => ['Accept: */*'],
'authorization' => [
sprintf('Authorization: Bearer %s', $accessToken),
],
],
$response->getRequestOptions()['normalized_headers']
);
$this->assertSame('{"message": "Response from actual API."}', $response->getContent());

$response = $this->httpClient->request('GET', 'https://superbrave.nl/api');

$this->assertSame(
array(
'authorization' => array(
sprintf('Bearer %s', $accessToken),
),
),
$response->getRequestOptions()['headers']
[
'accept' => ['Accept: */*'],
'authorization' => [
sprintf('Authorization: Bearer %s', $accessToken),
],
],
$response->getRequestOptions()['normalized_headers']
);
$this->assertSame('{"message": "Another response from actual API."}', $response->getContent());
}
Expand Down Expand Up @@ -168,8 +171,10 @@ public function testRequestWithAuthZeroAuthenticationUnsuccessful()
$response = $this->httpClient->request('GET', 'https://superbrave.nl/api');

$this->assertSame(
array(),
$response->getRequestOptions()['headers']
[
'accept' => ['Accept: */*'],
],
$response->getRequestOptions()['normalized_headers']
);
}

Expand All @@ -191,8 +196,10 @@ public function testRequestWithAuthZeroAuthenticationUnexpectedResponse()
$response = $this->httpClient->request('GET', 'https://superbrave.nl/api');

$this->assertSame(
array(),
$response->getRequestOptions()['headers']
[
'accept' => ['Accept: */*'],
],
$response->getRequestOptions()['normalized_headers']
);
}

Expand Down

0 comments on commit 75a1d3c

Please sign in to comment.