Skip to content

Commit 5e1b5e9

Browse files
committed
Add unit-tests for the Server config classs.
1 parent 1df3444 commit 5e1b5e9

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

tests/unit/Config/ServerTest.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Pdsinterop\Solid\Auth\Config;
4+
5+
use ArgumentCountError;
6+
use Pdsinterop\Solid\Auth\Enum\OpenId\OpenIdConnectMetadata as OidcMeta;
7+
use Pdsinterop\Solid\Auth\Exception\LogicException;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ServerTest extends TestCase
11+
{
12+
final public function testServerConfigShouldComplainWhenInstantiatedWithoutData() : void
13+
{
14+
$this->expectException(ArgumentCountError::class);
15+
$this->expectExceptionMessage('Too few arguments to function');
16+
17+
/** @noinspection PhpParamsInspection */
18+
new Server();
19+
}
20+
21+
final public function testServerConfigShouldInstantiatedWhenGivenData() : void
22+
{
23+
$actual = new Server([]);
24+
$expected = Server::class;
25+
26+
self::assertInstanceOf($expected, $actual);
27+
}
28+
29+
final public function testServerConfigShouldProvideRequiredPropertiesWhenAskedForRequiredProperties() : void
30+
{
31+
$server = new Server([]);
32+
$actual = $server->getRequired();
33+
34+
$expected = [
35+
OidcMeta::AUTHORIZATION_ENDPOINT,
36+
OidcMeta::ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED,
37+
OidcMeta::ISSUER,
38+
OidcMeta::JWKS_URI,
39+
OidcMeta::RESPONSE_TYPES_SUPPORTED,
40+
OidcMeta::SUBJECT_TYPES_SUPPORTED,
41+
];
42+
43+
self::assertEquals($expected, $actual);
44+
}
45+
46+
final public function testServerConfigShouldNotBeValidWhenMissingRequiredProperties() : void
47+
{
48+
$server = new Server([]);
49+
$actual = $server->validate();
50+
51+
self::assertFalse($actual);
52+
}
53+
54+
final public function testServerConfigShouldBeValidWhenGivenAllRequiredProperties() : void
55+
{
56+
$required = (new Server([]))->getRequired();
57+
$data = array_combine($required, $required);
58+
59+
$server = new Server($data);
60+
$server->getRequired();
61+
$actual = $server->validate();
62+
63+
self::assertTrue($actual);
64+
}
65+
66+
final public function testServerConfigShouldComplainWhenSerializedWithRequiredKeysMissing() : void
67+
{
68+
$this->expectException(LogicException::class);
69+
$this->expectExceptionMessage('Required properties have not been set: authorization_endpoint, id_token_signing_alg_values_supported, issuer, jwks_uri, response_types_supported, subject_types_supported');
70+
71+
$server = new Server([]);
72+
73+
$server->jsonSerialize();
74+
}
75+
76+
final public function testServerConfigShouldReturnArrayWhenSerializedWithRequiredKeysPresent() : array
77+
{
78+
$required = (new Server([]))->getRequired();
79+
$data = array_combine($required, $required);
80+
81+
$server = new Server($data);
82+
83+
$actual = $server->jsonSerialize();
84+
85+
self::assertIsArray($actual);
86+
87+
return $actual;
88+
}
89+
90+
/**
91+
* @depends testServerConfigShouldReturnArrayWhenSerializedWithRequiredKeysPresent
92+
*/
93+
final public function testServerConfigShouldReturnExpectedValuesWhenSerializedWithRequiredKeysPresent(array $actual)
94+
{
95+
self::assertEquals($actual, [
96+
'authorization_endpoint' => 'authorization_endpoint',
97+
'id_token_signing_alg_values_supported' => 'id_token_signing_alg_values_supported',
98+
'issuer' => 'issuer',
99+
'jwks_uri' => 'jwks_uri',
100+
'response_types_supported' => 'response_types_supported',
101+
'subject_types_supported' => 'subject_types_supported',
102+
]);
103+
}
104+
}

0 commit comments

Comments
 (0)