Skip to content

Commit eec415e

Browse files
committed
:octocat: minor test fixes & cleanup
1 parent b576096 commit eec415e

9 files changed

+79
-5
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Class OAuthProviderFactoryTest
4+
*
5+
* @created 11.04.2024
6+
* @author smiley <smiley@chillerlan.net>
7+
* @copyright 2024 smiley
8+
* @license MIT
9+
*
10+
* @phan-file-suppress PhanUndeclaredProperty
11+
*/
12+
declare(strict_types=1);
13+
14+
namespace chillerlan\OAuthTest\Core;
15+
16+
use chillerlan\OAuth\Core\OAuthInterface;
17+
use chillerlan\OAuth\OAuthProviderFactory;
18+
use chillerlan\OAuth\Providers\ProviderException;
19+
use chillerlan\OAuthTest\Providers\DummyOAuth1Provider;
20+
use chillerlan\OAuthTest\Providers\ProviderUnitTestHttpClientFactory;
21+
use chillerlan\PHPUnitHttp\HttpFactoryTrait;
22+
use PHPUnit\Framework\TestCase;
23+
use function realpath;
24+
25+
/**
26+
*
27+
*/
28+
class OAuthProviderFactoryTest extends TestCase{
29+
use HttpFactoryTrait;
30+
31+
protected const CACERT = __DIR__.'/../cacert.pem';
32+
33+
protected string $HTTP_CLIENT_FACTORY = ProviderUnitTestHttpClientFactory::class;
34+
35+
protected function setUp():void{
36+
$this->initFactories(realpath($this::CACERT));
37+
38+
$this->providerFactory = new OAuthProviderFactory(
39+
$this->httpClient,
40+
$this->requestFactory,
41+
$this->streamFactory,
42+
$this->uriFactory,
43+
);
44+
45+
}
46+
47+
public function testGetProvider():void{
48+
$provider = $this->providerFactory->getProvider(DummyOAuth1Provider::class);
49+
50+
$this::assertInstanceOf(OAuthInterface::class, $provider);
51+
}
52+
53+
public function testGetProviderInvalidProviderClassException():void{
54+
$this->expectException(ProviderException::class);
55+
$this->expectExceptionMessage('invalid provider class given');
56+
57+
$this->providerFactory->getProvider('\\some\\unknown\\class');
58+
}
59+
60+
}

tests/Core/UtilitiesTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use chillerlan\OAuth\Core\{OAuthInterface, Utilities};
1515
use PHPUnit\Framework\Attributes\DataProvider;
1616
use PHPUnit\Framework\TestCase;
17-
use ReflectionClass;
17+
use InvalidArgumentException, ReflectionClass;
1818

1919
/**
2020
*
@@ -37,6 +37,13 @@ public function testGetProvidersWithGivenPath():void{
3737
}
3838
}
3939

40+
public function testGetProvidersInvalidPathException():void{
41+
$this->expectException(InvalidArgumentException::class);
42+
$this->expectExceptionMessage('invalid $providerDir');
43+
44+
Utilities::getProviders('/foo');
45+
}
46+
4047
public static function encryptionFormatProvider():array{
4148
return [
4249
'binary' => [Utilities::ENCRYPT_FORMAT_BINARY],

tests/Providers/DummyOAuth1Provider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
final class DummyOAuth1Provider extends OAuth1Provider implements TokenInvalidate{
2020

21+
public const IDENTIFIER = 'DUMMYOAUTH1PROVIDER';
22+
2123
public const HEADERS_AUTH = ['foo' => 'bar'];
2224
public const HEADERS_API = ['foo' => 'bar'];
2325

tests/Providers/DummyOAuth2Provider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
final class DummyOAuth2Provider extends OAuth2Provider implements ClientCredentials, CSRFToken, PKCE, TokenRefresh, TokenInvalidate{
2020

21+
public const IDENTIFIER = 'DUMMYOAUTH2PROVIDER';
22+
2123
public const AUTH_METHOD = self::AUTH_METHOD_QUERY;
2224
public const HEADERS_AUTH = ['foo' => 'bar'];
2325
public const HEADERS_API = ['foo' => 'bar'];

tests/Providers/Live/AmazonAPITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function assertMeResponse(AuthenticatedUser $user):void{
3030
$this::assertMatchesRegularExpression('/[a-z\d.]+/i', $user->id);
3131
}
3232

33-
public function testUnauthorizedAccessException():void{
33+
public function testMeUnauthorizedAccessException():void{
3434
$token = $this->storage->getAccessToken($this->provider->name);
3535
// avoid refresh
3636
$token->expires = AccessToken::NEVER_EXPIRES;

tests/Providers/Live/OAuthProviderLiveTestAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function assertUnauthorizedAccessException(AccessToken $token):void{
6868
$this->provider->me();
6969
}
7070

71-
public function testUnauthorizedAccessException():void{
71+
public function testMeUnauthorizedAccessException():void{
7272

7373
if(!$this->provider instanceof UserInfo){
7474
$this::markTestSkipped('AuthenticatedUser N/A');

tests/Providers/Live/SteamAPITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function setUp():void{
3535
$this->id = $token->extraParams['id_int']; // SteamID64
3636
}
3737

38-
public function testUnauthorizedAccessException():void{
38+
public function testMeUnauthorizedAccessException():void{
3939
$this::markTestSkipped('N/A');
4040
}
4141

tests/Providers/Live/TwitterCCAPITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function getProviderFQCN():string{
2424
return TwitterCC::class;
2525
}
2626

27-
public function testUnauthorizedAccessException():void{
27+
public function testMeUnauthorizedAccessException():void{
2828
$this::markTestSkipped('N/A');
2929
}
3030

tests/Providers/Unit/OAuthProviderUnitTestAbstract.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function testMagicGet():void{
5252
$this::assertNull($this->provider->foo);
5353
}
5454

55+
public function testIdentifierIsNonEmpty():void{
56+
$this::assertNotEmpty($this->provider::IDENTIFIER);
57+
}
5558

5659
/*
5760
* request body

0 commit comments

Comments
 (0)