Skip to content

Commit af8ad91

Browse files
committed
Do unit test coverage
1 parent c3e35ec commit af8ad91

28 files changed

Lines changed: 2523 additions & 22 deletions

src/ValueAbstracts/KeyPairFilenameConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function getFileContent(string $filename): string
8989
throw new \RuntimeException(sprintf('File %s does not exist.', $filename));
9090
}
9191

92-
$fileContents = file_get_contents($filename);
92+
$fileContents = @file_get_contents($filename);
9393

9494
if ($fileContents === false) {
9595
throw new \RuntimeException(sprintf('Could not read file %s.', $filename));

src/VerifiableCredentials/VcDataModel/Claims/AbstractIdentifiedTypedClaimValue.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public function __construct(
2222
protected readonly TypeClaimValue $typeClaimValue,
2323
array $otherClaims = [],
2424
) {
25-
$this->data = array_merge(
25+
$this->data = array_replace(
2626
$otherClaims,
27-
[ClaimsEnum::Id->value => $this->id],
28-
[ClaimsEnum::Type->value => $this->typeClaimValue->jsonSerialize()],
27+
[
28+
ClaimsEnum::Id->value => $this->id,
29+
ClaimsEnum::Type->value => $this->typeClaimValue->jsonSerialize(),
30+
],
2931
);
3032
}
3133

src/VerifiableCredentials/VcDataModel/Claims/AbstractTypedClaimValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
protected readonly TypeClaimValue $typeClaimValue,
2121
array $otherClaims = [],
2222
) {
23-
$this->data = array_merge(
23+
$this->data = array_replace(
2424
$otherClaims,
2525
[ClaimsEnum::Type->value => $this->typeClaimValue->jsonSerialize()],
2626
);

src/VerifiableCredentials/VcDataModel2/Claims/VcCredentialStatusClaimBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function jsonSerialize(): array
4141

4242
public function getName(): string
4343
{
44-
return ClaimsEnum::Credential_Subject->value;
44+
return ClaimsEnum::Credential_Status->value;
4545
}
4646

4747

tests/src/CoreTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SimpleSAML\OpenID\Core;
1414
use SimpleSAML\OpenID\Core\Factories\ClientAssertionFactory;
1515
use SimpleSAML\OpenID\Core\Factories\IdTokenFactory;
16+
use SimpleSAML\OpenID\Core\Factories\LogoutTokenFactory;
1617
use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory;
1718
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
1819
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
@@ -44,6 +45,7 @@
4445
#[UsesClass(JwsSerializerManagerDecorator::class)]
4546
#[UsesClass(ClaimFactory::class)]
4647
#[UsesClass(IdTokenFactory::class)]
48+
#[UsesClass(LogoutTokenFactory::class)]
4749
final class CoreTest extends TestCase
4850
{
4951
protected \PHPUnit\Framework\MockObject\Stub $supportedAlgorithmsMock;
@@ -111,5 +113,10 @@ public function testCanBuildTools(): void
111113
IdTokenFactory::class,
112114
$sut->idTokenFactory(),
113115
);
116+
117+
$this->assertInstanceOf(
118+
LogoutTokenFactory::class,
119+
$sut->logoutTokenFactory(),
120+
);
114121
}
115122
}

tests/src/FederationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use SimpleSAML\OpenID\SupportedAlgorithms;
4646
use SimpleSAML\OpenID\SupportedSerializers;
4747
use SimpleSAML\OpenID\Utils\ArtifactFetcher;
48+
use SimpleSAML\OpenID\Utils\KeyPairResolver;
4849

4950
#[CoversClass(Federation::class)]
5051
#[UsesClass(ParsedJwsFactory::class)]
@@ -78,6 +79,7 @@
7879
#[UsesClass(TrustMarkValidator::class)]
7980
#[UsesClass(TrustMarkFetcher::class)]
8081
#[UsesClass(TrustMarkStatusResponseFetcher::class)]
82+
#[UsesClass(KeyPairResolver::class)]
8183
final class FederationTest extends TestCase
8284
{
8385
protected \PHPUnit\Framework\MockObject\Stub $supportedAlgorithmsMock;
@@ -166,5 +168,6 @@ public function testCanBuildTools(): void
166168
$this->assertInstanceOf(TrustMarkDelegationFactory::class, $sut->trustMarkDelegationFactory());
167169
$this->assertInstanceOf(TrustMarkValidator::class, $sut->trustMarkValidator());
168170
$this->assertInstanceOf(TrustMarkFetcher::class, $sut->trustMarkFetcher());
171+
$this->assertInstanceOf(KeyPairResolver::class, $sut->keyPairResolver());
169172
}
170173
}

tests/src/JwsTest.php

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\OpenID;
6+
7+
use DateInterval;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\Attributes\UsesClass;
10+
use PHPUnit\Framework\TestCase;
11+
use Psr\Log\LoggerInterface;
12+
use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator;
13+
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
14+
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
15+
use SimpleSAML\OpenID\Factories\ClaimFactory;
16+
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;
17+
use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory;
18+
use SimpleSAML\OpenID\Helpers;
19+
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
20+
use SimpleSAML\OpenID\Jws;
21+
use SimpleSAML\OpenID\Jws\Factories\JwsDecoratorBuilderFactory;
22+
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory;
23+
use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory;
24+
use SimpleSAML\OpenID\Jws\JwsDecoratorBuilder;
25+
use SimpleSAML\OpenID\Jws\JwsVerifierDecorator;
26+
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;
27+
use SimpleSAML\OpenID\SupportedAlgorithms;
28+
use SimpleSAML\OpenID\SupportedSerializers;
29+
30+
#[CoversClass(Jws::class)]
31+
#[UsesClass(AlgorithmManagerDecoratorFactory::class)]
32+
#[UsesClass(ClaimFactory::class)]
33+
#[UsesClass(DateIntervalDecoratorFactory::class)]
34+
#[UsesClass(JwsSerializerManagerDecoratorFactory::class)]
35+
#[UsesClass(JwksDecoratorFactory::class)]
36+
#[UsesClass(JwsDecoratorBuilderFactory::class)]
37+
#[UsesClass(JwsVerifierDecoratorFactory::class)]
38+
#[UsesClass(ParsedJwsFactory::class)]
39+
#[UsesClass(Helpers::class)]
40+
#[UsesClass(SupportedAlgorithms::class)]
41+
#[UsesClass(SupportedSerializers::class)]
42+
#[UsesClass(AlgorithmManagerDecorator::class)]
43+
#[UsesClass(JwsDecoratorBuilder::class)]
44+
#[UsesClass(JwsVerifierDecorator::class)]
45+
#[UsesClass(JwsSerializerManagerDecorator::class)]
46+
#[UsesClass(DateIntervalDecorator::class)]
47+
final class JwsTest extends TestCase
48+
{
49+
protected \PHPUnit\Framework\MockObject\Stub $supportedAlgorithmsMock;
50+
51+
protected \PHPUnit\Framework\MockObject\Stub $supportedSerializerMock;
52+
53+
protected DateInterval $timestampValidationLeeway;
54+
55+
protected \PHPUnit\Framework\MockObject\Stub $loggerMock;
56+
57+
58+
protected function setUp(): void
59+
{
60+
$this->supportedAlgorithmsMock = $this->createStub(SupportedAlgorithms::class);
61+
$this->supportedSerializerMock = $this->createStub(SupportedSerializers::class);
62+
$this->timestampValidationLeeway = new DateInterval('PT1M');
63+
$this->loggerMock = $this->createStub(LoggerInterface::class);
64+
}
65+
66+
67+
protected function sut(
68+
?SupportedAlgorithms $supportedAlgorithms = null,
69+
?SupportedSerializers $supportedSerializers = null,
70+
?DateInterval $timestampValidationLeeway = null,
71+
?LoggerInterface $logger = null,
72+
): Jws {
73+
$supportedAlgorithms ??= $this->supportedAlgorithmsMock;
74+
$supportedSerializers ??= $this->supportedSerializerMock;
75+
$timestampValidationLeeway ??= $this->timestampValidationLeeway;
76+
$logger ??= $this->loggerMock;
77+
78+
return new Jws(
79+
$supportedAlgorithms,
80+
$supportedSerializers,
81+
$timestampValidationLeeway,
82+
$logger,
83+
);
84+
}
85+
86+
87+
public function testCanCreateInstance(): void
88+
{
89+
$this->assertInstanceOf(
90+
Jws::class,
91+
$this->sut(),
92+
);
93+
}
94+
95+
96+
public function testCanBuildTools(): void
97+
{
98+
$sut = $this->sut();
99+
100+
$this->assertInstanceOf(
101+
DateIntervalDecoratorFactory::class,
102+
$sut->dateIntervalDecoratorFactory(),
103+
);
104+
105+
$this->assertInstanceOf(
106+
ParsedJwsFactory::class,
107+
$sut->parsedJwsFactory(),
108+
);
109+
110+
$this->assertInstanceOf(
111+
JwsDecoratorBuilder::class,
112+
$sut->jwsDecoratorBuilder(),
113+
);
114+
115+
$this->assertInstanceOf(
116+
JwsDecoratorBuilderFactory::class,
117+
$sut->jwsDecoratorBuilderFactory(),
118+
);
119+
120+
$this->assertInstanceOf(
121+
JwsSerializerManagerDecorator::class,
122+
$sut->jwsSerializerManagerDecorator(),
123+
);
124+
125+
$this->assertInstanceOf(
126+
JwsSerializerManagerDecoratorFactory::class,
127+
$sut->jwsSerializerManagerDecoratorFactory(),
128+
);
129+
130+
$this->assertInstanceOf(
131+
AlgorithmManagerDecorator::class,
132+
$sut->algorithmManagerDecorator(),
133+
);
134+
135+
$this->assertInstanceOf(
136+
AlgorithmManagerDecoratorFactory::class,
137+
$sut->algorithmManagerDecoratorFactory(),
138+
);
139+
140+
$this->assertInstanceOf(
141+
Helpers::class,
142+
$sut->helpers(),
143+
);
144+
145+
$this->assertInstanceOf(
146+
JwsVerifierDecorator::class,
147+
$sut->jwsVerifierDecorator(),
148+
);
149+
150+
$this->assertInstanceOf(
151+
JwsVerifierDecoratorFactory::class,
152+
$sut->jwsVerifierDecoratorFactory(),
153+
);
154+
155+
$this->assertInstanceOf(
156+
JwksDecoratorFactory::class,
157+
$sut->jwksDecoratorFactory(),
158+
);
159+
160+
$this->assertInstanceOf(
161+
ClaimFactory::class,
162+
$sut->claimFactory(),
163+
);
164+
}
165+
166+
167+
public function testLazyInitialization(): void
168+
{
169+
$sut = $this->sut();
170+
171+
$factory1 = $sut->dateIntervalDecoratorFactory();
172+
$factory2 = $sut->dateIntervalDecoratorFactory();
173+
$this->assertSame($factory1, $factory2);
174+
175+
$factory1 = $sut->parsedJwsFactory();
176+
$factory2 = $sut->parsedJwsFactory();
177+
$this->assertSame($factory1, $factory2);
178+
179+
$builder1 = $sut->jwsDecoratorBuilder();
180+
$builder2 = $sut->jwsDecoratorBuilder();
181+
$this->assertSame($builder1, $builder2);
182+
183+
$factory1 = $sut->jwsDecoratorBuilderFactory();
184+
$factory2 = $sut->jwsDecoratorBuilderFactory();
185+
$this->assertSame($factory1, $factory2);
186+
187+
$decorator1 = $sut->jwsSerializerManagerDecorator();
188+
$decorator2 = $sut->jwsSerializerManagerDecorator();
189+
$this->assertSame($decorator1, $decorator2);
190+
191+
$factory1 = $sut->jwsSerializerManagerDecoratorFactory();
192+
$factory2 = $sut->jwsSerializerManagerDecoratorFactory();
193+
$this->assertSame($factory1, $factory2);
194+
195+
$decorator1 = $sut->algorithmManagerDecorator();
196+
$decorator2 = $sut->algorithmManagerDecorator();
197+
$this->assertSame($decorator1, $decorator2);
198+
199+
$factory1 = $sut->algorithmManagerDecoratorFactory();
200+
$factory2 = $sut->algorithmManagerDecoratorFactory();
201+
$this->assertSame($factory1, $factory2);
202+
203+
$helpers1 = $sut->helpers();
204+
$helpers2 = $sut->helpers();
205+
$this->assertSame($helpers1, $helpers2);
206+
207+
$verifier1 = $sut->jwsVerifierDecorator();
208+
$verifier2 = $sut->jwsVerifierDecorator();
209+
$this->assertSame($verifier1, $verifier2);
210+
211+
$factory1 = $sut->jwsVerifierDecoratorFactory();
212+
$factory2 = $sut->jwsVerifierDecoratorFactory();
213+
$this->assertSame($factory1, $factory2);
214+
215+
$factory1 = $sut->jwksDecoratorFactory();
216+
$factory2 = $sut->jwksDecoratorFactory();
217+
$this->assertSame($factory1, $factory2);
218+
219+
$factory1 = $sut->claimFactory();
220+
$factory2 = $sut->claimFactory();
221+
$this->assertSame($factory1, $factory2);
222+
}
223+
}

0 commit comments

Comments
 (0)