Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Dec 3, 2021
1 parent 835c37f commit c151277
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
26 changes: 12 additions & 14 deletions tests/Auth/OAuth2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ class OAuth2Test extends TestCase
{
public function testGetAuthenticationUrl(): void
{
$client = new GuzzleClient();

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient(), '123', '456');
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=code', $auth->getAuthenticationUrl());
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=pin', $auth->getAuthenticationUrl('pin'));
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=code&state=draft', $auth->getAuthenticationUrl('code', 'draft'));

$auth = new OAuth2(new HttpClient([], $client), '456', '789');
$auth = new OAuth2(new HttpClient(), '456', '789');
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=456&response_type=pin', $auth->getAuthenticationUrl('pin'));
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=456&response_type=code', $auth->getAuthenticationUrl());
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=456&response_type=code&state=draft', $auth->getAuthenticationUrl('code', 'draft'));
Expand All @@ -39,7 +37,7 @@ public function testRequestAccessTokenBadStatusCode(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$auth->requestAccessToken('code', null);
}

Expand All @@ -51,7 +49,7 @@ public function testRequestAccessTokenWithCode(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$result = $auth->requestAccessToken('code', null);

$this->assertArrayHasKey('access_token', $result);
Expand All @@ -68,7 +66,7 @@ public function testRequestAccessTokenWithPin(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$result = $auth->requestAccessToken('code', 'pin');

$this->assertArrayHasKey('access_token', $result);
Expand All @@ -88,7 +86,7 @@ public function testRefreshTokenBadStatusCode(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$auth->refreshToken();
}

Expand All @@ -100,7 +98,7 @@ public function testRefreshToken(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$result = $auth->refreshToken();

$this->assertArrayHasKey('access_token', $result);
Expand All @@ -113,7 +111,7 @@ public function testSetAccessTokenNull(): void
$this->expectExceptionMessage('Token is not a valid json string.');

$client = new GuzzleClient();
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient(), '123', '456');
$auth->setAccessToken(null);
}

Expand All @@ -123,14 +121,14 @@ public function testSetAccessTokenEmpty(): void
$this->expectExceptionMessage('Access token could not be retrieved from the decoded json response.');

$client = new GuzzleClient();
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient(), '123', '456');
$auth->setAccessToken(['data']);
}

public function testCheckAccessTokenExpiredFromScratch(): void
{
$client = new GuzzleClient();
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient(), '123', '456');
$this->assertTrue($auth->checkAccessTokenExpired());
}

Expand All @@ -142,7 +140,7 @@ public function testCheckAccessTokenExpired(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$auth = new OAuth2(new HttpClient([], $client), '123', '456');
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
$auth->requestAccessToken('code', null);

$this->assertFalse($auth->checkAccessTokenExpired());
Expand All @@ -157,7 +155,7 @@ public function testAuthenticatedRequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler, $handler);

$auth = new OAuth2($httpClient, '123', '456');
$auth->requestAccessToken('code', null);
Expand Down
12 changes: 6 additions & 6 deletions tests/HttpClient/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testDoGETRequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->get($path, $parameters);

$result = $httpClient->parseResponse($response);
Expand All @@ -52,7 +52,7 @@ public function testDoPOSTRequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->post($path, $parameters);

$result = $httpClient->parseResponse($response);
Expand All @@ -74,7 +74,7 @@ public function testDoPOSTRequestWithMultipart(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->post($path, $parameters);

$result = $httpClient->parseResponse($response);
Expand All @@ -93,7 +93,7 @@ public function testDoPUTRequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->put($path, $parameters);

$result = $httpClient->parseResponse($response);
Expand All @@ -112,7 +112,7 @@ public function testDoDELETERequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->delete($path, $parameters);

$result = $httpClient->parseResponse($response);
Expand All @@ -131,7 +131,7 @@ public function testDoCustomRequest(): void
$handler = HandlerStack::create($mock);
$client = new GuzzleClient(['handler' => $handler]);

$httpClient = new HttpClient([], $client);
$httpClient = new HttpClient([], $client, $handler);
$response = $httpClient->performRequest($path, $options, 'HEAD');

$result = $httpClient->parseResponse($response);
Expand Down

0 comments on commit c151277

Please sign in to comment.