Skip to content

Commit 71b0d66

Browse files
committed
🚿 coverage
1 parent 3a13a22 commit 71b0d66

15 files changed

+78
-21
lines changed

src/Core/AccessToken.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function set_expires(DateTime|DateInterval|int|null $expires = null):v
122122

123123
// clamp max expiry
124124
if($this->expires > $max){
125-
$this->expires = $max;
125+
$this->expires = $max; // @codeCoverageIgnore
126126
}
127127

128128
}

src/Core/OAuthProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ final protected function getMeResponseData(string $endpoint, array|null $params
484484
$this->handleMeResponseError($response);
485485

486486
/** @noinspection PhpUnreachableStatementInspection this is here because phpstan silly */
487-
return [];
487+
return []; // @codeCoverageIgnore
488488
}
489489

490490
/**

src/Core/PKCETrait.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ final public function setCodeChallenge(array $params, string $challengeMethod):a
6161
*/
6262
final public function setCodeVerifier(array $params):array{
6363

64-
if(!$this instanceof PKCE){
65-
throw new ProviderException('PKCE challenge not supported');
66-
}
67-
6864
if(!isset($params['grant_type'], $params['code']) || $params['grant_type'] !== 'authorization_code'){
6965
throw new ProviderException('invalid authorization request body');
7066
}
@@ -120,7 +116,7 @@ final public function generateChallenge(string $verifier, string $challengeMetho
120116
$verifier = match($challengeMethod){
121117
PKCE::CHALLENGE_METHOD_S256 => hash('sha256', $verifier, true),
122118
// no other hash methods yet
123-
default => throw new ProviderException('invalid PKCE challenge method'),
119+
default => throw new ProviderException('invalid PKCE challenge method'), // @codeCoverageIgnore
124120
};
125121

126122
return sodium_bin2base64($verifier, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING);

src/Core/TokenInvalidateTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function invalidateAccessToken(AccessToken|null $token = null, string|nul
3838

3939
// @link https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
4040
if(!in_array($type, ['access_token', 'refresh_token'], true)){
41-
throw new ProviderException(sprintf('invalid token type "%s"', $type));
41+
throw new ProviderException(sprintf('invalid token type "%s"', $type)); // @codeCoverageIgnore
4242
}
4343

4444
$tokenToInvalidate = ($token ?? $this->storage->getAccessToken($this->name));
@@ -59,7 +59,7 @@ public function invalidateAccessToken(AccessToken|null $token = null, string|nul
5959
// ok, let's see if we got a response body
6060
// @link https://datatracker.ietf.org/doc/html/rfc7009#section-2.2.1
6161
if(str_contains($response->getHeaderLine('content-type'), 'json')){
62-
$json = MessageUtil::decodeJSON($response);
62+
$json = MessageUtil::decodeJSON($response, true);
6363

6464
if(isset($json['error'])){
6565
throw new ProviderException($json['error']);

src/Core/Utilities.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function encrypt(string $data, string $keyHex, int $format = self:
101101
self::ENCRYPT_FORMAT_BINARY => $nonce.$box,
102102
self::ENCRYPT_FORMAT_BASE64 => sodium_bin2base64($nonce.$box, SODIUM_BASE64_VARIANT_ORIGINAL),
103103
self::ENCRYPT_FORMAT_HEX => sodium_bin2hex($nonce.$box),
104-
default => throw new InvalidArgumentException('invalid format'),
104+
default => throw new InvalidArgumentException('invalid format'), // @codeCoverageIgnore
105105
};
106106

107107
sodium_memzero($data);
@@ -125,7 +125,7 @@ public static function decrypt(string $encrypted, string $keyHex, int $format =
125125
self::ENCRYPT_FORMAT_BINARY => $encrypted,
126126
self::ENCRYPT_FORMAT_BASE64 => sodium_base642bin($encrypted, SODIUM_BASE64_VARIANT_ORIGINAL),
127127
self::ENCRYPT_FORMAT_HEX => sodium_hex2bin($encrypted),
128-
default => throw new InvalidArgumentException('invalid format'),
128+
default => throw new InvalidArgumentException('invalid format'), // @codeCoverageIgnore
129129
};
130130

131131
$nonce = substr($bin, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);

src/Providers/BigCartel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function invalidateAccessToken(AccessToken|null $token = null, string|nul
7272
return true;
7373
}
7474

75-
return false;
75+
return false; // @codeCoverageIgnore
7676
}
7777

7878
/**

src/Providers/DeviantArt.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function invalidateAccessToken(AccessToken|null $token = null, string|nul
105105
return true;
106106
}
107107

108-
return false;
108+
return false; // @codeCoverageIgnore
109109
}
110110

111111
}

src/Storage/FileStorage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected function loadFile(string $key, string $provider):string|null{
203203
$contents = file_get_contents($path);
204204

205205
if($contents === false){
206-
throw new OAuthStorageException('file_get_contents() error');
206+
throw new OAuthStorageException('file_get_contents() error'); // @codeCoverageIgnore
207207
}
208208

209209
return $contents;

tests/Providers/Unit/BigCartelTest.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace chillerlan\OAuthTest\Providers\Unit;
1313

14-
use chillerlan\OAuth\Core\{AccessToken, TokenInvalidate};
14+
use chillerlan\OAuth\Core\AccessToken;
1515
use chillerlan\OAuth\Providers\BigCartel;
1616
use chillerlan\OAuthTest\Attributes\Provider;
1717

@@ -22,11 +22,6 @@
2222
final class BigCartelTest extends OAuth2ProviderUnitTestAbstract{
2323

2424
public function testTokenInvalidate():void{
25-
26-
if(!$this->provider instanceof TokenInvalidate){
27-
$this::markTestSkipped('TokenInvalidate N/A');
28-
}
29-
3025
// BigCartel expects the account id set in the token and responds with a 204
3126
$this->setMockResponse($this->responseFactory->createResponse(204));
3227

@@ -37,4 +32,8 @@ public function testTokenInvalidate():void{
3732
$this::assertFalse($this->storage->hasAccessToken($this->provider->getName()));
3833
}
3934

35+
public function testTokenInvalidateFailed():void{
36+
$this::markTestIncomplete();
37+
}
38+
4039
}

tests/Providers/Unit/DeviantArtTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ public function testTokenInvalidate():void{
5050
$this::assertSame('still here', $this->provider->getStorage()->getAccessToken($this->provider->getName())->accessToken);
5151
}
5252

53+
public function testTokenInvalidateFailedWithException():void{
54+
$this->markTestSkipped('N/A');
55+
}
56+
5357
}

tests/Providers/Unit/OAuth1Test.php

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ public function testMeUnknownErrorException():void{
2626
$this->markTestSkipped('N/A');
2727
}
2828

29+
public function testTokenInvalidateFailedWithException():void{
30+
$this->markTestSkipped('N/A');
31+
}
32+
2933
}

tests/Providers/Unit/OAuth2Test.php

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ public function testMeUnknownErrorException():void{
2626
$this->markTestSkipped('N/A');
2727
}
2828

29+
public function testTokenInvalidateFailedWithException():void{
30+
$this->markTestSkipped('N/A');
31+
}
32+
2933
}

tests/Providers/Unit/OAuthProviderUnitTestAbstract.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function testTokenInvalidate():void{
213213

214214
$token = $this->getTestToken();
215215

216-
$this->provider->storeAccessToken($this->getTestToken());
216+
$this->provider->storeAccessToken($token);
217217

218218
$this::assertTrue($this->storage->hasAccessToken($this->provider->getName()));
219219
$this::assertTrue($this->provider->invalidateAccessToken());
@@ -231,6 +231,44 @@ public function testTokenInvalidate():void{
231231
$this::assertSame('still here', $this->provider->getStorage()->getAccessToken($this->provider->getName())->accessToken);
232232
}
233233

234+
public function testTokenInvalidateFailed():void{
235+
236+
if(!$this->provider instanceof TokenInvalidate){
237+
$this::markTestSkipped('TokenInvalidate N/A');
238+
}
239+
240+
$token = $this->getTestToken();
241+
242+
$this->provider->storeAccessToken($token);
243+
244+
$this->setMockResponse($this->responseFactory->createResponse(404));
245+
246+
$this::assertFalse($this->provider->invalidateAccessToken());
247+
}
248+
249+
public function testTokenInvalidateFailedWithException():void{
250+
251+
if(!$this->provider instanceof TokenInvalidate){
252+
$this::markTestSkipped('TokenInvalidate N/A');
253+
}
254+
255+
$this->expectException(ProviderException::class);
256+
$this->expectExceptionMessage('whatever');
257+
258+
$token = $this->getTestToken();
259+
260+
$this->provider->storeAccessToken($token);
261+
262+
$response = $this->responseFactory
263+
->createResponse(404)
264+
->withHeader('Content-Type', 'application/json')
265+
->withBody($this->streamFactory->createStream('{"error":"whatever"}'));
266+
267+
$this->setMockResponse($response);
268+
269+
$this->provider->invalidateAccessToken();
270+
}
271+
234272
public function testTokenInvalidateNoTokenException():void{
235273

236274
if(!$this->provider instanceof TokenInvalidate){

tests/Providers/Unit/StripeTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ public function testTokenInvalidate():void{
2424
$this::markTestIncomplete();
2525
}
2626

27+
public function testTokenInvalidateFailed():void{
28+
$this::markTestIncomplete();
29+
}
30+
31+
public function testTokenInvalidateFailedWithException():void{
32+
$this::markTestIncomplete();
33+
}
34+
2735
}

tests/Providers/Unit/VimeoTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ public function testTokenInvalidate():void{
5050
$this::assertSame('still here', $this->provider->getStorage()->getAccessToken($this->provider->getName())->accessToken);
5151
}
5252

53+
public function testTokenInvalidateFailedWithException():void{
54+
$this->markTestSkipped('N/A');
55+
}
56+
5357
}

0 commit comments

Comments
 (0)