Skip to content

Commit 19b045c

Browse files
authored
Merge pull request #1148 from lcobucci/phpunit_strict
PHPUnit: apply `failOnAllIssues=true`
2 parents 462c850 + 06210b5 commit 19b045c

File tree

12 files changed

+67
-52
lines changed

12 files changed

+67
-52
lines changed

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
"psr/clock": "^1.0"
2424
},
2525
"require-dev": {
26-
"infection/infection": "^0.32.0",
27-
"lcobucci/clock": "^3.3.1",
28-
"lcobucci/coding-standard": "^11.1",
29-
"phpbench/phpbench": "^1.4.1",
26+
"infection/infection": "^0.32.3",
27+
"lcobucci/clock": "^3.5.0",
28+
"lcobucci/coding-standard": "^11.2",
29+
"phpbench/phpbench": "^1.4.3",
3030
"phpstan/extension-installer": "^1.4.3",
31-
"phpstan/phpstan": "^2.1.22",
31+
"phpstan/phpstan": "^2.1.38",
3232
"phpstan/phpstan-deprecation-rules": "^2.0.3",
33-
"phpstan/phpstan-phpunit": "^2.0.7",
34-
"phpstan/phpstan-strict-rules": "^2.0.6",
35-
"phpunit/phpunit": "^12.3.0"
33+
"phpstan/phpstan-phpunit": "^2.0.12",
34+
"phpstan/phpstan-strict-rules": "^2.0.8",
35+
"phpunit/phpunit": "^12.5.8",
36+
"sebastian/recursion-context": "^7.0.1"
3637
},
3738
"suggest": {
3839
"lcobucci/clock": ">= 3.2"

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
colors="true"
55
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutTodoAnnotatedTests="true"
76
beStrictAboutChangesToGlobalState="true"
87
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutTestsThatDoNotTestAnything="true"
99
requireCoverageMetadata="true"
10-
failOnRisky="true"
11-
failOnEmptyTestSuite="true"
10+
failOnAllIssues="true"
11+
displayDetailsOnAllIssues="true"
1212
cacheDirectory=".phpunit.cache"
13-
displayDetailsOnTestsThatTriggerWarnings="true"
14-
displayDetailsOnTestsThatTriggerNotices="true"
15-
displayDetailsOnTestsThatTriggerErrors="true"
16-
displayDetailsOnTestsThatTriggerDeprecations="true"
17-
displayDetailsOnIncompleteTests="true"
18-
displayDetailsOnSkippedTests="true"
1913
>
2014
<testsuites>
2115
<testsuite name="tests">
2216
<directory>tests</directory>
2317
</testsuite>
2418
</testsuites>
25-
2619
<source>
2720
<include>
28-
<directory suffix=".php">src</directory>
21+
<directory>src</directory>
2922
</include>
3023
</source>
3124
</phpunit>

tests/ConfigurationTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Lcobucci\JWT\Validation\Constraint;
1919
use Lcobucci\JWT\Validator;
2020
use PHPUnit\Framework\Attributes as PHPUnit;
21-
use PHPUnit\Framework\MockObject\MockObject;
21+
use PHPUnit\Framework\MockObject\Stub;
2222
use PHPUnit\Framework\TestCase;
2323

2424
#[PHPUnit\CoversClass(Configuration::class)]
@@ -29,22 +29,22 @@
2929
#[PHPUnit\UsesClass(\Lcobucci\JWT\Validation\Validator::class)]
3030
final class ConfigurationTest extends TestCase
3131
{
32-
private Parser&MockObject $parser;
33-
private Signer&MockObject $signer;
34-
private Encoder&MockObject $encoder;
35-
private Decoder&MockObject $decoder;
36-
private Validator&MockObject $validator;
37-
private Constraint&MockObject $validationConstraints;
32+
private Parser&Stub $parser;
33+
private Signer&Stub $signer;
34+
private Encoder&Stub $encoder;
35+
private Decoder&Stub $decoder;
36+
private Validator&Stub $validator;
37+
private Constraint&Stub $validationConstraints;
3838

3939
#[PHPUnit\Before]
4040
public function createDependencies(): void
4141
{
42-
$this->signer = $this->createMock(Signer::class);
43-
$this->encoder = $this->createMock(Encoder::class);
44-
$this->decoder = $this->createMock(Decoder::class);
45-
$this->parser = $this->createMock(Parser::class);
46-
$this->validator = $this->createMock(Validator::class);
47-
$this->validationConstraints = $this->createMock(Constraint::class);
42+
$this->signer = self::createStub(Signer::class);
43+
$this->encoder = self::createStub(Encoder::class);
44+
$this->decoder = self::createStub(Decoder::class);
45+
$this->parser = self::createStub(Parser::class);
46+
$this->validator = self::createStub(Validator::class);
47+
$this->validationConstraints = self::createStub(Constraint::class);
4848
}
4949

5050
#[PHPUnit\Test]
@@ -102,7 +102,7 @@ public function builderShouldCreateABuilderWithCustomizedEncoderAndClaimFactory(
102102
#[PHPUnit\Test]
103103
public function builderShouldUseBuilderFactoryWhenThatIsConfigured(): void
104104
{
105-
$builder = $this->createMock(Builder::class);
105+
$builder = self::createStub(Builder::class);
106106

107107
$config = Configuration::forSymmetricSigner(
108108
new KeyDumpSigner(),
@@ -207,7 +207,7 @@ public function validationConstraintsShouldReturnTheConfiguredValidator(): void
207207
#[PHPUnit\Test]
208208
public function customClaimFormatterCanBeUsed(): void
209209
{
210-
$formatter = $this->createMock(ClaimsFormatter::class);
210+
$formatter = self::createStub(ClaimsFormatter::class);
211211
$config = Configuration::forSymmetricSigner(
212212
new KeyDumpSigner(),
213213
InMemory::plainText('private'),

tests/Token/BuilderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function initializeDependencies(): void
4242
#[PHPUnit\Test]
4343
public function withClaimShouldRaiseExceptionWhenTryingToConfigureARegisteredClaim(): void
4444
{
45+
$this->encoder->expects($this->never())->method(self::anything());
46+
$this->signer->expects($this->never())->method(self::anything());
47+
4548
$builder = Builder::new($this->encoder, new MicrosecondBasedDateConversion());
4649

4750
$this->expectException(RegisteredClaimGiven::class);
@@ -107,6 +110,9 @@ public function getTokenShouldReturnACompletelyConfigureToken(): void
107110
#[PHPUnit\Test]
108111
public function immutability(): void
109112
{
113+
$this->encoder->expects($this->never())->method(self::anything());
114+
$this->signer->expects($this->never())->method(self::anything());
115+
110116
$map = new SplObjectStorage();
111117
$builder = Builder::new($this->encoder, new MicrosecondBasedDateConversion());
112118
$map[$builder] = true;

tests/Token/ParserTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ private function createParser(): Parser
4141
#[PHPUnit\Test]
4242
public function parseMustRaiseExceptionWhenTokenDoesNotHaveThreeParts(): void
4343
{
44+
$this->decoder->expects($this->never())->method(self::anything());
45+
4446
$parser = $this->createParser();
4547

4648
$this->expectException(InvalidTokenStructure::class);
@@ -52,6 +54,8 @@ public function parseMustRaiseExceptionWhenTokenDoesNotHaveThreeParts(): void
5254
#[PHPUnit\Test]
5355
public function parseMustRaiseExceptionWhenTokenDoesNotHaveHeaders(): void
5456
{
57+
$this->decoder->expects($this->never())->method(self::anything());
58+
5559
$parser = $this->createParser();
5660

5761
$this->expectException(InvalidTokenStructure::class);
@@ -63,6 +67,8 @@ public function parseMustRaiseExceptionWhenTokenDoesNotHaveHeaders(): void
6367
#[PHPUnit\Test]
6468
public function parseMustRaiseExceptionWhenTokenDoesNotHaveClaims(): void
6569
{
70+
$this->decoder->expects($this->never())->method(self::anything());
71+
6672
$parser = $this->createParser();
6773

6874
$this->expectException(InvalidTokenStructure::class);
@@ -74,6 +80,8 @@ public function parseMustRaiseExceptionWhenTokenDoesNotHaveClaims(): void
7480
#[PHPUnit\Test]
7581
public function parseMustRaiseExceptionWhenTokenDoesNotHaveSignature(): void
7682
{
83+
$this->decoder->expects($this->never())->method(self::anything());
84+
7785
$parser = $this->createParser();
7886

7987
$this->expectException(InvalidTokenStructure::class);
@@ -108,7 +116,8 @@ public function parseMustRaiseExceptionWhenHeaderCannotBeDecoded(): void
108116
#[PHPUnit\Test]
109117
public function parseMustRaiseExceptionWhenDealingWithNonArrayHeaders(): void
110118
{
111-
$this->decoder->method('jsonDecode')
119+
$this->decoder->expects($this->once())
120+
->method('jsonDecode')
112121
->willReturn('A very invalid header');
113122

114123
$parser = $this->createParser();
@@ -122,8 +131,9 @@ public function parseMustRaiseExceptionWhenDealingWithNonArrayHeaders(): void
122131
#[PHPUnit\Test]
123132
public function parseMustRaiseExceptionWhenDealingWithHeadersThatHaveEmptyStringKeys(): void
124133
{
125-
$this->decoder->method('jsonDecode')
126-
->willReturn(['' => 'foo']);
134+
$this->decoder->expects($this->once())
135+
->method('jsonDecode')
136+
->willReturn(['' => 'foo']);
127137

128138
$parser = $this->createParser();
129139

@@ -136,8 +146,9 @@ public function parseMustRaiseExceptionWhenDealingWithHeadersThatHaveEmptyString
136146
#[PHPUnit\Test]
137147
public function parseMustRaiseExceptionWhenHeaderIsFromAnEncryptedToken(): void
138148
{
139-
$this->decoder->method('jsonDecode')
140-
->willReturn(['enc' => 'AAA']);
149+
$this->decoder->expects($this->once())
150+
->method('jsonDecode')
151+
->willReturn(['enc' => 'AAA']);
141152

142153
$parser = $this->createParser();
143154

@@ -150,8 +161,9 @@ public function parseMustRaiseExceptionWhenHeaderIsFromAnEncryptedToken(): void
150161
#[PHPUnit\Test]
151162
public function parseMustRaiseExceptionWhenDealingWithNonArrayClaims(): void
152163
{
153-
$this->decoder->method('jsonDecode')
154-
->willReturnOnConsecutiveCalls(['typ' => 'JWT'], 'A very invalid claim set');
164+
$this->decoder->expects($this->exactly(2))
165+
->method('jsonDecode')
166+
->willReturnOnConsecutiveCalls(['typ' => 'JWT'], 'A very invalid claim set');
155167

156168
$parser = $this->createParser();
157169

@@ -164,8 +176,9 @@ public function parseMustRaiseExceptionWhenDealingWithNonArrayClaims(): void
164176
#[PHPUnit\Test]
165177
public function parseMustRaiseExceptionWhenDealingWithClaimsThatHaveEmptyStringKeys(): void
166178
{
167-
$this->decoder->method('jsonDecode')
168-
->willReturnOnConsecutiveCalls(['typ' => 'JWT'], ['' => 'foo']);
179+
$this->decoder->expects($this->exactly(2))
180+
->method('jsonDecode')
181+
->willReturnOnConsecutiveCalls(['typ' => 'JWT'], ['' => 'foo']);
169182

170183
$parser = $this->createParser();
171184

tests/Validation/Constraint/HasClaimTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function assertShouldRaiseExceptionWhenClaimIsNotSet(): void
5252
#[PHPUnit\Test]
5353
public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void
5454
{
55-
$token = $this->createMock(Token::class);
55+
$token = self::createStub(Token::class);
5656
$constraint = new HasClaim('claimId');
5757

5858
$this->expectException(ConstraintViolation::class);

tests/Validation/Constraint/HasClaimWithValueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void
6868
$this->expectException(ConstraintViolation::class);
6969
$this->expectExceptionMessage('You should pass a plain token');
7070

71-
$constraint->assert($this->createMock(Token::class));
71+
$constraint->assert(self::createStub(Token::class));
7272
}
7373

7474
#[PHPUnit\Test]

tests/Validation/Constraint/SignedWithTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public function createDependencies(): void
3636
#[PHPUnit\Test]
3737
public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void
3838
{
39+
$this->signer->expects($this->never())->method(self::anything());
40+
3941
$constraint = new SignedWith($this->signer, $this->key);
4042

4143
$this->expectException(ConstraintViolation::class);
4244
$this->expectExceptionMessage('You should pass a plain token');
4345

44-
$constraint->assert($this->createMock(Token::class));
46+
$constraint->assert(self::createStub(Token::class));
4547
}
4648

4749
#[PHPUnit\Test]

tests/Validation/Constraint/SignedWithUntilDateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void
6868
$this->expectException(ConstraintViolation::class);
6969
$this->expectExceptionMessage('You should pass a plain token');
7070

71-
$constraint->assert($this->createMock(Token::class));
71+
$constraint->assert(self::createStub(Token::class));
7272
}
7373

7474
#[PHPUnit\Test]

0 commit comments

Comments
 (0)