Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 16, 2024
1 parent 194286f commit b8ac5fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function parseCredentialsArray(string|array|callable $credentials): void
match ($arrayLength) {
1 => $this->setRefreshToken($credentials[0]),
2 => $this->setClientCredentialsPair($credentials[0], $credentials[1]),
default => throw new InvalidArgumentException('Invalid credentials. Check documentation/readme. '),
default => throw new InvalidArgumentException('Invalid credentials. Check documentation/readme.'),
};

return;
Expand Down
33 changes: 24 additions & 9 deletions tests/Unit/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@
});
});

/*
test('throws exception with an invalid auth type', function () {
//$this->expectException(\Illuminate\Validation\ValidationException::class);
//$this->expectExceptionMessage('The selected auth type is invalid');
test('throws exception with invalid credentials', function () {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid credentials. Check documentation/readme.');

app(RefreshToken::class)(
'https://example.com/oauth/token',
Expand All @@ -214,17 +213,33 @@
),
);
});
*/

test('throws exception with an invalid auth type', function () {
$this->expectException(\Illuminate\Validation\ValidationException::class);
$this->expectExceptionMessage('The selected auth type is invalid.');

app(RefreshToken::class)(
'https://example.com/oauth/token',
new Credentials([
'my_client_id',
'my_client_secret',
]),
new Options(
scopes: ['scope1', 'scope2'],
authType: 'invalid',
),
);
});

test('throws exception with an invalid token type', function () {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('customCallback must be set when using AUTH_TYPE_CUSTOM');

app(RefreshToken::class)(
'https://example.com/oauth/token',
new Credentials(['my_token']),
new Options(
scopes: ['scope1', 'scope2'],
scopes: ['scope1', 'scope2'],
tokenType: AccessToken::TOKEN_TYPE_CUSTOM,
),
);
Expand All @@ -242,9 +257,9 @@
);

expect($accessToken->getAccessToken())->toBe('this_is_my_access_token_from_body_refresh_token')
->and($accessToken->getExpiresIn())->toBe(3540)
->and($accessToken->getExpiresAt())->toBeInstanceOf(Carbon::class)
->and($accessToken->getCustomCallback())->toBeNull();
->and($accessToken->getExpiresIn())->toBe(3540)
->and($accessToken->getExpiresAt())->toBeInstanceOf(Carbon::class)
->and($accessToken->getCustomCallback())->toBeNull();
});

})->done(assignee: 'pelmered');

0 comments on commit b8ac5fa

Please sign in to comment.