Skip to content

Commit aed161e

Browse files
committed
fix: grant type tests
1 parent eff60aa commit aed161e

4 files changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fschmtt\Keycloak\Test\Unit\OAuth\GrantType;
6+
7+
use Fschmtt\Keycloak\OAuth\GrantType\ClientCredentials;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\TestCase;
10+
11+
#[CoversClass(ClientCredentials::class)]
12+
class ClientCredentialsTest extends TestCase
13+
{
14+
public function testRequestParams(): void
15+
{
16+
$clientCredentials = new ClientCredentials(
17+
'client-id',
18+
'client-secret',
19+
'realm',
20+
'scope',
21+
);
22+
23+
static::assertSame([
24+
'grant_type' => 'client_credentials',
25+
'client_id' => 'client-id',
26+
'client_secret' => 'client-secret',
27+
'scope' => 'scope',
28+
], $clientCredentials->toRequestParams());
29+
}
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fschmtt\Keycloak\Test\Unit\OAuth\GrantType;
6+
7+
use Fschmtt\Keycloak\OAuth\GrantType\Password;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\TestCase;
10+
11+
#[CoversClass(Password::class)]
12+
class PasswordTest extends TestCase
13+
{
14+
public function testRequestParams(): void
15+
{
16+
$password = new Password(
17+
'username',
18+
'password',
19+
'client-id',
20+
'realn',
21+
'client-secret',
22+
'scope',
23+
);
24+
25+
static::assertSame([
26+
'grant_type' => 'password',
27+
'username' => 'username',
28+
'password' => 'password',
29+
'client_id' => 'client-id',
30+
'client_secret' => 'client-secret',
31+
'scope' => 'scope',
32+
], $password->toRequestParams());
33+
}
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fschmtt\Keycloak\Test\Unit\OAuth\GrantType;
6+
7+
use Fschmtt\Keycloak\OAuth\GrantType\RefreshToken;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\TestCase;
10+
11+
#[CoversClass(RefreshToken::class)]
12+
class RefreshTokenTest extends TestCase
13+
{
14+
public function testRequestParams(): void
15+
{
16+
$refreshToken = new RefreshToken(
17+
'refresh-token',
18+
'client-id',
19+
'realm',
20+
'client-secret',
21+
'scope',
22+
);
23+
24+
static::assertSame([
25+
'grant_type' => 'refresh_token',
26+
'refresh_token' => 'refresh-token',
27+
'client_id' => 'client-id',
28+
'client_secret' => 'client-secret',
29+
'scope' => 'scope',
30+
], $refreshToken->toRequestParams());
31+
}
32+
}

tests/Unit/OAuth/GrantTypeTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fschmtt\Keycloak\Test\Unit\OAuth;
6+
7+
use Fschmtt\Keycloak\OAuth\GrantType;
8+
use Fschmtt\Keycloak\OAuth\GrantType\RefreshToken;
9+
use PHPUnit\Framework\Attributes\CoversClass;
10+
use PHPUnit\Framework\TestCase;
11+
12+
#[CoversClass(GrantType::class)]
13+
class GrantTypeTest extends TestCase
14+
{
15+
public function testPassword(): void
16+
{
17+
$password = new GrantType\Password(
18+
'username',
19+
'password',
20+
'client-id',
21+
'realm',
22+
'client-secret',
23+
'scope',
24+
);
25+
26+
$grantType = GrantType::password(
27+
'username',
28+
'password',
29+
'client-id',
30+
'realm',
31+
'client-secret',
32+
'scope',
33+
);
34+
35+
static::assertEquals($password, $grantType);
36+
}
37+
38+
public function testClientCredentials(): void
39+
{
40+
$clientCredentials = new GrantType\ClientCredentials(
41+
'client-id',
42+
'client-secret',
43+
'realm',
44+
'scope',
45+
);
46+
47+
$grantType = GrantType::clientCredentials(
48+
'client-id',
49+
'client-secret',
50+
'realm',
51+
'scope',
52+
);
53+
54+
static::assertEquals($clientCredentials, $grantType);
55+
}
56+
57+
public function testRefreshToken(): void
58+
{
59+
$refreshToken = new RefreshToken(
60+
'refresh-token',
61+
'client-id',
62+
'realm',
63+
'client-secret',
64+
'scope',
65+
);
66+
67+
$grantType = GrantType::refreshToken(
68+
'refresh-token',
69+
'client-id',
70+
'realm',
71+
'client-secret',
72+
'scope',
73+
);
74+
75+
static::assertEquals($refreshToken, $grantType);
76+
}
77+
}

0 commit comments

Comments
 (0)