-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathIgnoreBooleanAlwaysImpossibleAssertTest.php
More file actions
54 lines (48 loc) · 1.97 KB
/
Copy pathIgnoreBooleanAlwaysImpossibleAssertTest.php
File metadata and controls
54 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Tests\Unit\PhpStan;
use PHPStan\Analyser\IgnoreErrorExtension;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Rules\Comparison\ImpossibleCheckTypeFunctionCallRule;
use PHPStan\Rules\Rule;
/**
* This covers `function.alreadyNarrowedType` error handling in the `IgnoreBooleanAlways` PHPStan extension class.
* `RuleTestCase` allows only one `Rule` class, so separate `TestCase`s are needed for errors generated by other rules.
* Note that the base class covers testing the suppression of the warning, and is included via `extends`.
* This class covers the non-suppression of warnings in other contexts, which requires detailing the expected warnings.
*
* @covers \Sabberworm\CSS\PhpStan\IgnoreBooleanAlways
*/
final class IgnoreBooleanAlwaysImpossibleAssertTest extends IgnoreBooleanAlwaysTestBase
{
/**
* @return ImpossibleCheckTypeFunctionCallRule
*/
protected function getRule(): Rule
{
// If the class is renamed or removed in the next major release of PHPStan, we'll deal with it then.
// @phpstan-ignore phpstanApi.classConstant
return self::getContainer()->getByType(ImpossibleCheckTypeFunctionCallRule::class);
}
/**
* @test
*/
public function warningIsRetainedForPointlessAssert(): void
{
// Skip the test in PHP/PHPStan configurations that don't have the required components.
// It is good enough to test for those that do.
if (!\interface_exists(IgnoreErrorExtension::class)) {
self::markTestSkipped('This is testing the testers, and only needs to run whenever possible.');
}
// Second argument is array of expected warnings.
$this->analyse(
[self::FIXTURES_DIR . 'alwaystrue-pointlessassert.php'],
[
[
'Call to function is_int() with int will always evaluate to true.',
7,
],
]
);
}
}