Skip to content

Commit b2877f1

Browse files
staabmondrejmirtes
authored andcommitted
Simplify tests in which treatPhpDocTypesAsCertain is always true
1 parent 9876b29 commit b2877f1

File tree

6 files changed

+14
-73
lines changed

6 files changed

+14
-73
lines changed

tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
class DoWhileLoopConstantConditionRuleTest extends RuleTestCase
1212
{
1313

14-
private bool $treatPhpDocTypesAsCertain = true;
15-
1614
protected function getRule(): Rule
1715
{
1816
return new DoWhileLoopConstantConditionRule(
@@ -21,20 +19,15 @@ protected function getRule(): Rule
2119
self::createReflectionProvider(),
2220
$this->getTypeSpecifier(),
2321
[],
24-
$this->treatPhpDocTypesAsCertain,
22+
$this->shouldTreatPhpDocTypesAsCertain(),
2523
),
26-
$this->treatPhpDocTypesAsCertain,
24+
$this->shouldTreatPhpDocTypesAsCertain(),
2725
),
28-
$this->treatPhpDocTypesAsCertain,
26+
$this->shouldTreatPhpDocTypesAsCertain(),
2927
true,
3028
);
3129
}
3230

33-
protected function shouldTreatPhpDocTypesAsCertain(): bool
34-
{
35-
return $this->treatPhpDocTypesAsCertain;
36-
}
37-
3831
public function testRule(): void
3932
{
4033
$this->analyse([__DIR__ . '/data/do-while-loop.php'], [

tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
class LogicalXorConstantConditionRuleTest extends RuleTestCase
1212
{
1313

14-
private bool $treatPhpDocTypesAsCertain;
15-
1614
private bool $reportAlwaysTrueInLastCondition = false;
1715

1816
protected function getRule(): TRule
@@ -23,11 +21,11 @@ protected function getRule(): TRule
2321
self::createReflectionProvider(),
2422
$this->getTypeSpecifier(),
2523
[],
26-
$this->treatPhpDocTypesAsCertain,
24+
$this->shouldTreatPhpDocTypesAsCertain(),
2725
),
28-
$this->treatPhpDocTypesAsCertain,
26+
$this->shouldTreatPhpDocTypesAsCertain(),
2927
),
30-
$this->treatPhpDocTypesAsCertain,
28+
$this->shouldTreatPhpDocTypesAsCertain(),
3129
$this->reportAlwaysTrueInLastCondition,
3230
true,
3331
);
@@ -36,7 +34,6 @@ protected function getRule(): TRule
3634
public function testRule(): void
3735
{
3836
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
39-
$this->treatPhpDocTypesAsCertain = true;
4037
$this->analyse([__DIR__ . '/data/logical-xor.php'], [
4138
[
4239
'Left side of xor is always true.',

tests/PHPStan/Rules/Comparison/WhileLoopAlwaysFalseConditionRuleTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
class WhileLoopAlwaysFalseConditionRuleTest extends RuleTestCase
1212
{
1313

14-
private bool $treatPhpDocTypesAsCertain = true;
15-
1614
protected function getRule(): Rule
1715
{
1816
return new WhileLoopAlwaysFalseConditionRule(
@@ -21,20 +19,15 @@ protected function getRule(): Rule
2119
self::createReflectionProvider(),
2220
$this->getTypeSpecifier(),
2321
[],
24-
$this->treatPhpDocTypesAsCertain,
22+
$this->shouldTreatPhpDocTypesAsCertain(),
2523
),
26-
$this->treatPhpDocTypesAsCertain,
24+
$this->shouldTreatPhpDocTypesAsCertain(),
2725
),
28-
$this->treatPhpDocTypesAsCertain,
26+
$this->shouldTreatPhpDocTypesAsCertain(),
2927
true,
3028
);
3129
}
3230

33-
protected function shouldTreatPhpDocTypesAsCertain(): bool
34-
{
35-
return $this->treatPhpDocTypesAsCertain;
36-
}
37-
3831
public function testRule(): void
3932
{
4033
$this->analyse([__DIR__ . '/data/while-loop-false.php'], [

tests/PHPStan/Rules/Comparison/WhileLoopAlwaysTrueConditionRuleTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
class WhileLoopAlwaysTrueConditionRuleTest extends RuleTestCase
1212
{
1313

14-
private bool $treatPhpDocTypesAsCertain = true;
15-
1614
protected function getRule(): Rule
1715
{
1816
return new WhileLoopAlwaysTrueConditionRule(
@@ -21,20 +19,15 @@ protected function getRule(): Rule
2119
self::createReflectionProvider(),
2220
$this->getTypeSpecifier(),
2321
[],
24-
$this->treatPhpDocTypesAsCertain,
22+
$this->shouldTreatPhpDocTypesAsCertain(),
2523
),
26-
$this->treatPhpDocTypesAsCertain,
24+
$this->shouldTreatPhpDocTypesAsCertain(),
2725
),
28-
$this->treatPhpDocTypesAsCertain,
26+
$this->shouldTreatPhpDocTypesAsCertain(),
2927
true,
3028
);
3129
}
3230

33-
protected function shouldTreatPhpDocTypesAsCertain(): bool
34-
{
35-
return $this->treatPhpDocTypesAsCertain;
36-
}
37-
3831
public function testRule(): void
3932
{
4033
$this->analyse([__DIR__ . '/data/while-loop-true.php'], [

tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
class ArrayValuesRuleTest extends RuleTestCase
1313
{
1414

15-
private bool $treatPhpDocTypesAsCertain = true;
16-
1715
protected function getRule(): Rule
1816
{
1917
return new ArrayValuesRule(
2018
self::createReflectionProvider(),
21-
$this->treatPhpDocTypesAsCertain,
19+
$this->shouldTreatPhpDocTypesAsCertain(),
2220
true,
2321
);
2422
}

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,23 @@
1616
class NullCoalesceRuleTest extends RuleTestCase
1717
{
1818

19-
private bool $treatPhpDocTypesAsCertain;
20-
2119
protected function getRule(): Rule
2220
{
2321
return new NullCoalesceRule(new IssetCheck(
2422
new PropertyDescriptor(),
2523
new PropertyReflectionFinder(),
2624
true,
27-
$this->treatPhpDocTypesAsCertain,
25+
$this->shouldTreatPhpDocTypesAsCertain(),
2826
));
2927
}
3028

31-
protected function shouldTreatPhpDocTypesAsCertain(): bool
32-
{
33-
return $this->treatPhpDocTypesAsCertain;
34-
}
35-
3629
public function shouldNarrowMethodScopeFromConstructor(): bool
3730
{
3831
return true;
3932
}
4033

4134
public function testCoalesceRule(): void
4235
{
43-
$this->treatPhpDocTypesAsCertain = true;
4436
$errors = [
4537
[
4638
'Property CoalesceRule\FooCoalesce::$string (string) on left side of ?? is not nullable.',
@@ -146,7 +138,6 @@ public function testCoalesceRule(): void
146138

147139
public function testCoalesceAssignRule(): void
148140
{
149-
$this->treatPhpDocTypesAsCertain = true;
150141
$this->analyse([__DIR__ . '/data/null-coalesce-assign.php'], [
151142
[
152143
'Property CoalesceAssignRule\FooCoalesce::$string (string) on left side of ??= is not nullable.',
@@ -209,13 +200,11 @@ public function testCoalesceAssignRule(): void
209200

210201
public function testNullsafe(): void
211202
{
212-
$this->treatPhpDocTypesAsCertain = true;
213203
$this->analyse([__DIR__ . '/data/null-coalesce-nullsafe.php'], []);
214204
}
215205

216206
public function testVariableCertaintyInNullCoalesce(): void
217207
{
218-
$this->treatPhpDocTypesAsCertain = true;
219208
$this->analyse([__DIR__ . '/data/variable-certainty-null.php'], [
220209
[
221210
'Variable $scalar on left side of ?? always exists and is not nullable.',
@@ -234,7 +223,6 @@ public function testVariableCertaintyInNullCoalesce(): void
234223

235224
public function testVariableCertaintyInNullCoalesceAssign(): void
236225
{
237-
$this->treatPhpDocTypesAsCertain = true;
238226
$this->analyse([__DIR__ . '/data/variable-certainty-null-assign.php'], [
239227
[
240228
'Variable $scalar on left side of ??= always exists and is not nullable.',
@@ -253,7 +241,6 @@ public function testVariableCertaintyInNullCoalesceAssign(): void
253241

254242
public function testNullCoalesceInGlobalScope(): void
255243
{
256-
$this->treatPhpDocTypesAsCertain = true;
257244
$this->analyse([__DIR__ . '/data/null-coalesce-global-scope.php'], [
258245
[
259246
'Variable $bar on left side of ?? always exists and is not nullable.',
@@ -264,15 +251,12 @@ public function testNullCoalesceInGlobalScope(): void
264251

265252
public function testBug5933(): void
266253
{
267-
$this->treatPhpDocTypesAsCertain = true;
268254
$this->analyse([__DIR__ . '/data/bug-5933.php'], []);
269255
}
270256

271257
#[RequiresPhp('>= 8.0')]
272258
public function testBug7109(): void
273259
{
274-
$this->treatPhpDocTypesAsCertain = true;
275-
276260
$this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [
277261
[
278262
'Using nullsafe property access "?->aaa" on left side of ?? is unnecessary. Use -> instead.',
@@ -299,8 +283,6 @@ public function testBug7109(): void
299283

300284
public function testBug7190(): void
301285
{
302-
$this->treatPhpDocTypesAsCertain = true;
303-
304286
$this->analyse([__DIR__ . '/../Properties/data/bug-7190.php'], [
305287
[
306288
'Offset int on array<int, int> on left side of ?? always exists and is not nullable.',
@@ -311,8 +293,6 @@ public function testBug7190(): void
311293

312294
public function testBug7318(): void
313295
{
314-
$this->treatPhpDocTypesAsCertain = true;
315-
316296
$this->analyse([__DIR__ . '/../Properties/data/bug-7318.php'], [
317297
[
318298
"Offset 'unique' on array{unique: bool} on left side of ?? always exists and is not nullable.",
@@ -323,50 +303,37 @@ public function testBug7318(): void
323303

324304
public function testBug7968(): void
325305
{
326-
$this->treatPhpDocTypesAsCertain = true;
327-
328306
$this->analyse([__DIR__ . '/data/bug-7968.php'], []);
329307
}
330308

331309
public function testBug8084(): void
332310
{
333-
$this->treatPhpDocTypesAsCertain = true;
334-
335311
$this->analyse([__DIR__ . '/data/bug-8084.php'], []);
336312
}
337313

338314
public function testBug10577(): void
339315
{
340-
$this->treatPhpDocTypesAsCertain = true;
341-
342316
$this->analyse([__DIR__ . '/data/bug-10577.php'], []);
343317
}
344318

345319
public function testBug11708(): void
346320
{
347-
$this->treatPhpDocTypesAsCertain = true;
348-
349321
$this->analyse([__DIR__ . '/data/bug-11708.php'], []);
350322
}
351323

352324
public function testBug10610(): void
353325
{
354-
$this->treatPhpDocTypesAsCertain = true;
355-
356326
$this->analyse([__DIR__ . '/data/bug-10610.php'], []);
357327
}
358328

359329
#[RequiresPhp('>= 8.4')]
360330
public function testBug12553(): void
361331
{
362-
$this->treatPhpDocTypesAsCertain = true;
363332
$this->analyse([__DIR__ . '/data/bug-12553.php'], []);
364333
}
365334

366335
public function testIssetAfterRememberedConstructor(): void
367336
{
368-
$this->treatPhpDocTypesAsCertain = true;
369-
370337
$this->analyse([__DIR__ . '/data/isset-after-remembered-constructor.php'], [
371338
[
372339
'Property IssetOrCoalesceOnNonNullableInitializedProperty\User::$string on left side of ?? is not nullable nor uninitialized.',

0 commit comments

Comments
 (0)