Skip to content

Commit

Permalink
Merge pull request #803 from kenjis/fix-test-config-fqcn
Browse files Browse the repository at this point in the history
test: use short classname for `config()`
  • Loading branch information
kenjis authored Aug 29, 2023
2 parents 63891c7 + a90e40a commit 05e033d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testCheckNoToken(): void

$this->assertFalse($result->isOK());
$this->assertSame(
\lang('Auth.noToken', [config(AuthJWT::class)->authenticatorHeader]),
\lang('Auth.noToken', [config('AuthJWT')->authenticatorHeader]),
$result->reason()
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Authentication/Filters/JWTFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected function setUp(): void
$_SESSION = [];

// Add JWT Authenticator
$config = config(Auth::class);
/** @var Auth $config */
$config = config('Auth');
$config->authenticators['jwt'] = JWT::class;

// Register our filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testDecodeInvalidTokenExceptionUnexpectedValueException(): void
$token = $this->generateJWT();

// Change algorithm and it makes the key invalid.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['alg'] = 'ES256';

$adapter = new FirebaseAdapter();
Expand Down Expand Up @@ -110,7 +111,8 @@ public function testDecodeInvalidArgumentException(): void
$token = $this->generateJWT();

// Set invalid key.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => '',
'secret' => '',
Expand All @@ -128,7 +130,8 @@ public function testEncodeLogicExceptionLogicException(): void
$this->expectExceptionMessage('Cannot encode JWT: Algorithm not supported');

// Set unsupported algorithm.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['alg'] = 'PS256';

$adapter = new FirebaseAdapter();
Expand Down
21 changes: 14 additions & 7 deletions tests/Unit/Authentication/JWT/JWTManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function testGenerateTokenPayload(array $data): void
$manager = $this->createJWTManager();
$payload = $manager->parse($token);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$expected = [
'iss' => $config->defaultClaims['iss'],
'sub' => '1',
Expand Down Expand Up @@ -121,7 +122,8 @@ public function testIssuePayload(array $data): void
$manager = $this->createJWTManager();
$payload = $manager->parse($token);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$expected = [
'iss' => $config->defaultClaims['iss'],
'user_id' => '1',
Expand All @@ -137,7 +139,8 @@ public function testIssueSetKid(): void
$manager = $this->createJWTManager();

// Set kid
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['kid'] = 'Key01';

$payload = [
Expand Down Expand Up @@ -181,7 +184,8 @@ public function testIssueWithAsymmetricKey(): void
{
$manager = $this->createJWTManager();

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => 'RS256', // algorithm.
'public' => '', // Public Key
Expand Down Expand Up @@ -257,7 +261,8 @@ private function decodeJWT(string $token, $part): array

public function testParseCanDecodeTokenSignedByOldKey(): void
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'] = [
[
'kid' => 'Key01',
Expand Down Expand Up @@ -294,7 +299,8 @@ public function testParseCanDecodeTokenSignedByOldKey(): void

public function testParseCanSpecifyKey(): void
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['mobile'] = [
[
'kid' => 'Key01',
Expand Down Expand Up @@ -329,7 +335,8 @@ private function generateJWTWithAsymmetricKey(): string
{
$manager = $this->createJWTManager();

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => 'RS256', // algorithm.
'public' => <<<'EOD'
Expand Down

0 comments on commit 05e033d

Please sign in to comment.