Skip to content

Commit 7cfc02e

Browse files
committed
Other attempt at removing checkAlwaysTrue* from tests
1 parent eb0504c commit 7cfc02e

19 files changed

+12
-537
lines changed

tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php

+1-119
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
class ImpossibleInstanceOfRuleTest extends RuleTestCase
1313
{
1414

15-
private bool $checkAlwaysTrueInstanceOf;
16-
1715
private bool $treatPhpDocTypesAsCertain;
1816

1917
private bool $reportAlwaysTrueInLastCondition = false;
2018

2119
protected function getRule(): Rule
2220
{
2321
return new ImpossibleInstanceOfRule(
24-
$this->checkAlwaysTrueInstanceOf,
2522
$this->treatPhpDocTypesAsCertain,
2623
$this->reportAlwaysTrueInLastCondition,
24+
true,
2725
);
2826
}
2927

@@ -34,7 +32,6 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool
3432

3533
public function testInstanceof(): void
3634
{
37-
$this->checkAlwaysTrueInstanceOf = true;
3835
$this->treatPhpDocTypesAsCertain = true;
3936
$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%</>.';
4037
$this->analyse(
@@ -195,107 +192,8 @@ public function testInstanceof(): void
195192
);
196193
}
197194

198-
public function testInstanceofWithoutAlwaysTrue(): void
199-
{
200-
$this->checkAlwaysTrueInstanceOf = false;
201-
$this->treatPhpDocTypesAsCertain = true;
202-
203-
$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%</>.';
204-
$this->analyse(
205-
[__DIR__ . '/data/impossible-instanceof.php'],
206-
[
207-
[
208-
'Instanceof between ImpossibleInstanceOf\Dolor and ImpossibleInstanceOf\Lorem will always evaluate to false.',
209-
71,
210-
],
211-
[
212-
'Instanceof between string and ImpossibleInstanceOf\Foo will always evaluate to false.',
213-
94,
214-
],
215-
[
216-
'Instanceof between string and \'str\' will always evaluate to false.',
217-
98,
218-
],
219-
[
220-
'Instanceof between ImpossibleInstanceOf\Test|null and ImpossibleInstanceOf\Lorem will always evaluate to false.',
221-
119,
222-
],
223-
[
224-
'Instanceof between ImpossibleInstanceOf\Test|null and ImpossibleInstanceOf\Lorem will always evaluate to false.',
225-
137,
226-
],
227-
[
228-
'Instanceof between ImpossibleInstanceOf\Test|null and ImpossibleInstanceOf\Lorem will always evaluate to false.',
229-
155,
230-
],
231-
[
232-
'Instanceof between callable and ImpossibleInstanceOf\FinalClassWithoutInvoke will always evaluate to false.',
233-
204,
234-
],
235-
[
236-
'Instanceof between *NEVER* and ImpossibleInstanceOf\Lorem will always evaluate to false.',
237-
228,
238-
],
239-
[
240-
'Instanceof between *NEVER* and ImpossibleInstanceOf\Foo will always evaluate to false.',
241-
234,
242-
],
243-
[
244-
'Instanceof between *NEVER* and ImpossibleInstanceOf\Bar will always evaluate to false.',
245-
240,
246-
//$tipText,
247-
],
248-
[
249-
'Instanceof between object and Exception will always evaluate to false.',
250-
303,
251-
],
252-
[
253-
'Instanceof between object and InvalidArgumentException will always evaluate to false.',
254-
307,
255-
],
256-
[
257-
'Instanceof between ImpossibleInstanceOf\Bar and ImpossibleInstanceOf\BarChild will always evaluate to false.',
258-
318,
259-
],
260-
[
261-
'Instanceof between ImpossibleInstanceOf\Bar and ImpossibleInstanceOf\BarGrandChild will always evaluate to false.',
262-
322,
263-
],
264-
/*[
265-
'Instanceof between mixed and int results in an error.',
266-
353,
267-
],
268-
[
269-
'Instanceof between mixed and ImpossibleInstanceOf\InvalidTypeTest|int results in an error.',
270-
362,
271-
],*/
272-
[
273-
'Instanceof between T of Exception and Error will always evaluate to false.',
274-
404,
275-
$tipText,
276-
],
277-
[
278-
'Instanceof between class-string<DateTimeInterface> and DateTimeInterface will always evaluate to false.',
279-
418,
280-
$tipText,
281-
],
282-
[
283-
'Instanceof between class-string<DateTimeInterface> and class-string<DateTimeInterface> will always evaluate to false.',
284-
419,
285-
$tipText,
286-
],
287-
[
288-
'Instanceof between class-string<DateTimeInterface> and \'DateTimeInterface\' will always evaluate to false.',
289-
432,
290-
$tipText,
291-
],
292-
],
293-
);
294-
}
295-
296195
public function testDoNotReportTypesFromPhpDocs(): void
297196
{
298-
$this->checkAlwaysTrueInstanceOf = true;
299197
$this->treatPhpDocTypesAsCertain = false;
300198
$this->analyse([__DIR__ . '/data/impossible-instanceof-not-phpdoc.php'], [
301199
[
@@ -319,7 +217,6 @@ public function testDoNotReportTypesFromPhpDocs(): void
319217

320218
public function testReportTypesFromPhpDocs(): void
321219
{
322-
$this->checkAlwaysTrueInstanceOf = true;
323220
$this->treatPhpDocTypesAsCertain = true;
324221
$this->analyse([__DIR__ . '/data/impossible-instanceof-not-phpdoc.php'], [
325222
[
@@ -353,21 +250,18 @@ public function testReportTypesFromPhpDocs(): void
353250

354251
public function testBug3096(): void
355252
{
356-
$this->checkAlwaysTrueInstanceOf = true;
357253
$this->treatPhpDocTypesAsCertain = true;
358254
$this->analyse([__DIR__ . '/data/bug-3096.php'], []);
359255
}
360256

361257
public function testBug6213(): void
362258
{
363-
$this->checkAlwaysTrueInstanceOf = true;
364259
$this->treatPhpDocTypesAsCertain = true;
365260
$this->analyse([__DIR__ . '/data/bug-6213.php'], []);
366261
}
367262

368263
public function testBug5333(): void
369264
{
370-
$this->checkAlwaysTrueInstanceOf = true;
371265
$this->treatPhpDocTypesAsCertain = false;
372266
$this->analyse([__DIR__ . '/data/bug-5333.php'], []);
373267
}
@@ -378,7 +272,6 @@ public function testBug8042(): void
378272
$this->markTestSkipped('This test needs PHP 8.0');
379273
}
380274

381-
$this->checkAlwaysTrueInstanceOf = true;
382275
$this->treatPhpDocTypesAsCertain = true;
383276
$this->analyse([__DIR__ . '/data/bug-8042.php'], [
384277
[
@@ -400,14 +293,12 @@ public function testBug7721(): void
400293
$this->markTestSkipped('This test needs PHP 8.1');
401294
}
402295

403-
$this->checkAlwaysTrueInstanceOf = true;
404296
$this->treatPhpDocTypesAsCertain = true;
405297
$this->analyse([__DIR__ . '/data/bug-7721.php'], []);
406298
}
407299

408300
public function testUnreachableIfBranches(): void
409301
{
410-
$this->checkAlwaysTrueInstanceOf = true;
411302
$this->treatPhpDocTypesAsCertain = true;
412303
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-if-branches.php'], [
413304
[
@@ -432,7 +323,6 @@ public function testUnreachableIfBranches(): void
432323

433324
public function testIfBranchesDoNotReportPhpDoc(): void
434325
{
435-
$this->checkAlwaysTrueInstanceOf = true;
436326
$this->treatPhpDocTypesAsCertain = false;
437327
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-if-branches-not-phpdoc.php'], [
438328
[
@@ -454,7 +344,6 @@ public function testIfBranchesDoNotReportPhpDoc(): void
454344

455345
public function testIfBranchesReportPhpDoc(): void
456346
{
457-
$this->checkAlwaysTrueInstanceOf = true;
458347
$this->treatPhpDocTypesAsCertain = true;
459348
$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%</>.';
460349
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-if-branches-not-phpdoc.php'], [
@@ -492,7 +381,6 @@ public function testIfBranchesReportPhpDoc(): void
492381

493382
public function testUnreachableTernaryElse(): void
494383
{
495-
$this->checkAlwaysTrueInstanceOf = true;
496384
$this->treatPhpDocTypesAsCertain = true;
497385
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-ternary-else-branch.php'], [
498386
[
@@ -508,7 +396,6 @@ public function testUnreachableTernaryElse(): void
508396

509397
public function testTernaryElseDoNotReportPhpDoc(): void
510398
{
511-
$this->checkAlwaysTrueInstanceOf = true;
512399
$this->treatPhpDocTypesAsCertain = false;
513400
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-ternary-else-branch-not-phpdoc.php'], [
514401
[
@@ -528,7 +415,6 @@ public function testTernaryElseDoNotReportPhpDoc(): void
528415

529416
public function testTernaryElseReportPhpDoc(): void
530417
{
531-
$this->checkAlwaysTrueInstanceOf = true;
532418
$this->treatPhpDocTypesAsCertain = true;
533419
$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%</>.';
534420
$this->analyse([__DIR__ . '/../Comparison/data/unreachable-ternary-else-branch-not-phpdoc.php'], [
@@ -554,7 +440,6 @@ public function testTernaryElseReportPhpDoc(): void
554440

555441
public function testBug4689(): void
556442
{
557-
$this->checkAlwaysTrueInstanceOf = true;
558443
$this->treatPhpDocTypesAsCertain = false;
559444
$this->analyse([__DIR__ . '/data/bug-4689.php'], []);
560445
}
@@ -590,7 +475,6 @@ public function dataReportAlwaysTrueInLastCondition(): iterable
590475
*/
591476
public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void
592477
{
593-
$this->checkAlwaysTrueInstanceOf = true;
594478
$this->treatPhpDocTypesAsCertain = true;
595479
$this->reportAlwaysTrueInLastCondition = $reportAlwaysTrueInLastCondition;
596480
$this->analyse([__DIR__ . '/data/impossible-instanceof-report-always-true-last-condition.php'], $expectedErrors);
@@ -602,7 +486,6 @@ public function testBug10201(): void
602486
$this->markTestSkipped('This test needs PHP 8.1');
603487
}
604488

605-
$this->checkAlwaysTrueInstanceOf = true;
606489
$this->treatPhpDocTypesAsCertain = true;
607490
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-10201.php'], [
608491
[
@@ -614,7 +497,6 @@ public function testBug10201(): void
614497

615498
public function testBug3632(): void
616499
{
617-
$this->checkAlwaysTrueInstanceOf = true;
618500
$this->treatPhpDocTypesAsCertain = true;
619501

620502
$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%</>.';

tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ protected function getRule(): Rule
2626
$this->treatPhpDocTypesAsCertain,
2727
),
2828
$this->treatPhpDocTypesAsCertain,
29-
true,
3029
),
3130
$this->treatPhpDocTypesAsCertain,
3231
$this->reportAlwaysTrueInLastCondition,

tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ protected function getRule(): Rule
2626
$this->treatPhpDocTypesAsCertain,
2727
),
2828
$this->treatPhpDocTypesAsCertain,
29-
true,
3029
),
3130
$this->treatPhpDocTypesAsCertain,
3231
$this->reportAlwaysTrueInLastCondition,

tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ protected function getRule(): Rule
2727
$this->treatPhpDocTypesAsCertain,
2828
),
2929
$this->treatPhpDocTypesAsCertain,
30-
true,
3130
),
3231
$this->treatPhpDocTypesAsCertain,
3332
$this->reportAlwaysTrueInLastCondition,

tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php

+1-32
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,21 @@
1212
class ConstantLooseComparisonRuleTest extends RuleTestCase
1313
{
1414

15-
private bool $checkAlwaysTrueStrictComparison;
16-
1715
private bool $treatPhpDocTypesAsCertain = true;
1816

1917
private bool $reportAlwaysTrueInLastCondition = false;
2018

2119
protected function getRule(): Rule
2220
{
2321
return new ConstantLooseComparisonRule(
24-
$this->checkAlwaysTrueStrictComparison,
2522
$this->treatPhpDocTypesAsCertain,
2623
$this->reportAlwaysTrueInLastCondition,
24+
true,
2725
);
2826
}
2927

3028
public function testRule(): void
3129
{
32-
$this->checkAlwaysTrueStrictComparison = false;
33-
$this->analyse([__DIR__ . '/data/loose-comparison.php'], [
34-
[
35-
"Loose comparison using == between 0 and '1' will always evaluate to false.",
36-
20,
37-
],
38-
[
39-
"Loose comparison using == between 0 and '1' will always evaluate to false.",
40-
27,
41-
],
42-
[
43-
"Loose comparison using == between 0 and '1' will always evaluate to false.",
44-
33,
45-
],
46-
[
47-
'Loose comparison using != between 3 and 3 will always evaluate to false.',
48-
48,
49-
'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%</>.',
50-
],
51-
]);
52-
}
53-
54-
public function testRuleAlwaysTrue(): void
55-
{
56-
$this->checkAlwaysTrueStrictComparison = true;
5730
$this->analyse([__DIR__ . '/data/loose-comparison.php'], [
5831
[
5932
"Loose comparison using == between 0 and '0' will always evaluate to true.",
@@ -90,7 +63,6 @@ public function testBug8485(): void
9063
$this->markTestSkipped('Test requires PHP 8.1.');
9164
}
9265

93-
$this->checkAlwaysTrueStrictComparison = true;
9466
$this->analyse([__DIR__ . '/data/bug-8485.php'], [
9567
[
9668
'Loose comparison using == between Bug8485\E::c and Bug8485\E::c will always evaluate to true.',
@@ -142,7 +114,6 @@ public function dataReportAlwaysTrueInLastCondition(): iterable
142114
*/
143115
public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void
144116
{
145-
$this->checkAlwaysTrueStrictComparison = true;
146117
$this->reportAlwaysTrueInLastCondition = $reportAlwaysTrueInLastCondition;
147118
$this->analyse([__DIR__ . '/data/loose-comparison-report-always-true-last-condition.php'], $expectedErrors);
148119
}
@@ -165,14 +136,12 @@ public function dataTreatPhpDocTypesAsCertain(): iterable
165136
*/
166137
public function testTreatPhpDocTypesAsCertain(bool $treatPhpDocTypesAsCertain, array $expectedErrors): void
167138
{
168-
$this->checkAlwaysTrueStrictComparison = true;
169139
$this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain;
170140
$this->analyse([__DIR__ . '/data/loose-comparison-treat-phpdoc-types.php'], $expectedErrors);
171141
}
172142

173143
public function testBug11694(): void
174144
{
175-
$this->checkAlwaysTrueStrictComparison = true;
176145
$this->analyse([__DIR__ . '/data/bug-11694.php'], [
177146
[
178147
'Loose comparison using == between 3 and int<10, 20> will always evaluate to false.',

tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ protected function getRule(): Rule
2424
$this->treatPhpDocTypesAsCertain,
2525
),
2626
$this->treatPhpDocTypesAsCertain,
27-
true,
2827
),
2928
$this->treatPhpDocTypesAsCertain,
3029
true,

tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ protected function getRule(): Rule
2727
$this->treatPhpDocTypesAsCertain,
2828
),
2929
$this->treatPhpDocTypesAsCertain,
30-
true,
3130
),
3231
$this->treatPhpDocTypesAsCertain,
3332
$this->reportAlwaysTrueInLastCondition,

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected function getRule(): Rule
2525
$this->treatPhpDocTypesAsCertain,
2626
),
2727
$this->treatPhpDocTypesAsCertain,
28-
true,
2928
),
3029
$this->treatPhpDocTypesAsCertain,
3130
true,

0 commit comments

Comments
 (0)