Skip to content

Commit c151277

Browse files
committed
Fix tests
1 parent 835c37f commit c151277

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

tests/Auth/OAuth2Test.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ class OAuth2Test extends TestCase
1515
{
1616
public function testGetAuthenticationUrl(): void
1717
{
18-
$client = new GuzzleClient();
19-
20-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
18+
$auth = new OAuth2(new HttpClient(), '123', '456');
2119
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=code', $auth->getAuthenticationUrl());
2220
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=pin', $auth->getAuthenticationUrl('pin'));
2321
$this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=123&response_type=code&state=draft', $auth->getAuthenticationUrl('code', 'draft'));
2422

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

42-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
40+
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
4341
$auth->requestAccessToken('code', null);
4442
}
4543

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

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

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

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

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

91-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
89+
$auth = new OAuth2(new HttpClient([], $client, $handler), '123', '456');
9290
$auth->refreshToken();
9391
}
9492

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

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

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

115113
$client = new GuzzleClient();
116-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
114+
$auth = new OAuth2(new HttpClient(), '123', '456');
117115
$auth->setAccessToken(null);
118116
}
119117

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

125123
$client = new GuzzleClient();
126-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
124+
$auth = new OAuth2(new HttpClient(), '123', '456');
127125
$auth->setAccessToken(['data']);
128126
}
129127

130128
public function testCheckAccessTokenExpiredFromScratch(): void
131129
{
132130
$client = new GuzzleClient();
133-
$auth = new OAuth2(new HttpClient([], $client), '123', '456');
131+
$auth = new OAuth2(new HttpClient(), '123', '456');
134132
$this->assertTrue($auth->checkAccessTokenExpired());
135133
}
136134

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

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

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

160-
$httpClient = new HttpClient([], $client);
158+
$httpClient = new HttpClient([], $client, $handler, $handler);
161159

162160
$auth = new OAuth2($httpClient, '123', '456');
163161
$auth->requestAccessToken('code', null);

tests/HttpClient/HttpClientTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testDoGETRequest(): void
3333
$handler = HandlerStack::create($mock);
3434
$client = new GuzzleClient(['handler' => $handler]);
3535

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

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

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

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

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

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

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

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

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

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

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

137137
$result = $httpClient->parseResponse($response);

0 commit comments

Comments
 (0)