Skip to content

Commit

Permalink
:octocat: use attribute to supply provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Apr 29, 2024
1 parent 2bb8a3a commit 9e9fdcb
Show file tree
Hide file tree
Showing 92 changed files with 231 additions and 373 deletions.
30 changes: 30 additions & 0 deletions tests/Attributes/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Class Provider
*
* @created 29.04.2024
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*/
declare(strict_types = 1);

namespace chillerlan\OAuthTest\Attributes;

use Attribute;

/**
* Supplies the provider class name
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class Provider{

public function __construct(
private readonly string $className,
){}

public function className():string{
return $this->className;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/AmazonAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
use chillerlan\OAuth\Core\{AccessToken, AuthenticatedUser, UnauthorizedAccessException};
use chillerlan\OAuth\Providers\Amazon;
use chillerlan\OAuth\Storage\MemoryStorage;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Amazon $provider
*/
#[Group('providerLiveTest')]
#[Provider(Amazon::class)]
final class AmazonAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Amazon::class;
}

protected function assertMeResponse(AuthenticatedUser $user):void{
$this::assertMatchesRegularExpression('/[a-z\d.]+/i', $user->id);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Providers/Live/BattleNetAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use chillerlan\OAuth\Core\AuthenticatedUser;
use chillerlan\OAuth\Providers\BattleNet;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;
use function explode;

Expand All @@ -21,12 +22,9 @@
*/
#[Group('shortTokenExpiry')]
#[Group('providerLiveTest')]
#[Provider(BattleNet::class)]
final class BattleNetAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return BattleNet::class;
}

protected function assertMeResponse(AuthenticatedUser $user):void{
$this::assertSame($this->TEST_USER, explode('#', $user->handle)[0]);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Providers/Live/BigCartelAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\BigCartel;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\BigCartel $provider
*/
#[Group('providerLiveTest')]
#[Provider(BigCartel::class)]
final class BigCartelAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return BigCartel::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/BitbucketAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Bitbucket;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Bitbucket $provider
*/
#[Group('providerLiveTest')]
#[Provider(Bitbucket::class)]
final class BitbucketAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Bitbucket::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/CodebergAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Codeberg;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Codeberg $provider
*/
#[Group('providerLiveTest')]
#[Provider(Codeberg::class)]
class CodebergAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Codeberg::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/DeezerAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Deezer;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Deezer $provider
*/
#[Group('shortTokenExpiry')]
#[Group('providerLiveTest')]
#[Provider(Deezer::class)]
final class DeezerAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Deezer::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/DeviantArtAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\DeviantArt;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\DeviantArt $provider
*/
#[Group('shortTokenExpiry')]
#[Group('providerLiveTest')]
#[Provider(DeviantArt::class)]
final class DeviantArtAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return DeviantArt::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/DiscogsAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Discogs;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Discogs $provider
*/
#[Group('providerLiveTest')]
#[Provider(Discogs::class)]
final class DiscogsAPITest extends OAuth1ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Discogs::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/DiscordAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@

use chillerlan\OAuth\Core\AccessToken;
use chillerlan\OAuth\Providers\Discord;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Discord $provider
*/
#[Group('providerLiveTest')]
#[Provider(Discord::class)]
final class DiscordAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Discord::class;
}

public function testRequestCredentialsToken():void{
$token = $this->provider->getClientCredentialsToken([Discord::SCOPE_CONNECTIONS, Discord::SCOPE_IDENTIFY]);

Expand Down
6 changes: 2 additions & 4 deletions tests/Providers/Live/FlickrAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Flickr;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Flickr $provider
*/
#[Group('providerLiveTest')]
#[Provider(Flickr::class)]
final class FlickrAPITest extends OAuth1ProviderLiveTestAbstract{

protected string $test_name;
protected string $test_id;

protected function getProviderFQCN():string{
return Flickr::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/FoursquareAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Foursquare;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Foursquare $provider
*/
#[Group('providerLiveTest')]
#[Provider(Foursquare::class)]
final class FoursquareAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Foursquare::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/GitHubAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\GitHub;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\GitHub $provider
*/
#[Group('providerLiveTest')]
#[Provider(GitHub::class)]
final class GitHubAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return GitHub::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/GitLabAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\GitLab;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\GitLab $provider
*/
#[Group('shortTokenExpiry')]
#[Group('providerLiveTest')]
#[Provider(GitLab::class)]
final class GitLabAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return GitLab::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/GiteaAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Gitea;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Gitea $provider
*/
#[Group('providerLiveTest')]
#[Provider(Gitea::class)]
class GiteaAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Gitea::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/GoogleAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@

use chillerlan\OAuth\Core\AuthenticatedUser;
use chillerlan\OAuth\Providers\Google;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Google $provider
*/
#[Group('shortTokenExpiry')]
#[Group('providerLiveTest')]
#[Provider(Google::class)]
final class GoogleAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Google::class;
}

protected function assertMeResponse(AuthenticatedUser $user):void{
$this::assertSame($this->TEST_USER, $user->email);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Providers/Live/GuildWars2APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
use chillerlan\OAuth\Core\AccessToken;
use chillerlan\OAuth\Core\AuthenticatedUser;
use chillerlan\OAuth\Providers\GuildWars2;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\GuildWars2 $provider
*/
#[Group('providerLiveTest')]
#[Provider(GuildWars2::class)]
final class GuildWars2APITest extends OAuth2ProviderLiveTestAbstract{

protected AccessToken $token;
protected string $tokenname;

protected function getProviderFQCN():string{
return GuildWars2::class;
}

protected function setUp():void{
parent::setUp();

Expand Down
6 changes: 2 additions & 4 deletions tests/Providers/Live/ImgurAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\Imgur;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\Imgur $provider
*/
#[Group('providerLiveTest')]
#[Provider(Imgur::class)]
final class ImgurAPITest extends OAuth2ProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return Imgur::class;
}

}
6 changes: 2 additions & 4 deletions tests/Providers/Live/LastFMAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
namespace chillerlan\OAuthTest\Providers\Live;

use chillerlan\OAuth\Providers\LastFM;
use chillerlan\OAuthTest\Attributes\Provider;
use PHPUnit\Framework\Attributes\Group;

/**
* @property \chillerlan\OAuth\Providers\LastFM $provider
*/
#[Group('providerLiveTest')]
#[Provider(LastFM::class)]
final class LastFMAPITest extends OAuthProviderLiveTestAbstract{

protected function getProviderFQCN():string{
return LastFM::class;
}

}
Loading

0 comments on commit 9e9fdcb

Please sign in to comment.