Skip to content

Commit a0c1364

Browse files
committed
Regression tests
1 parent 6b93db7 commit a0c1364

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\PHPUnit;
4+
5+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule;
6+
use PHPStan\Rules\Rule;
7+
use PHPStan\Testing\RuleTestCase;
8+
9+
/**
10+
* @extends RuleTestCase<ImpossibleCheckTypeMethodCallRule>
11+
*/
12+
class ImpossibleCheckTypeMethodCallRuleTest extends RuleTestCase
13+
{
14+
15+
protected function getRule(): Rule
16+
{
17+
return self::getContainer()->getByType(ImpossibleCheckTypeMethodCallRule::class);
18+
}
19+
20+
public function testRule(): void
21+
{
22+
$this->analyse([__DIR__ . '/data/impossible-assert-method-call.php'], [
23+
[
24+
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{} will always evaluate to true.',
25+
14,
26+
],
27+
[
28+
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{1, 2, 3} will always evaluate to false.',
29+
15,
30+
],
31+
]);
32+
}
33+
34+
/**
35+
* @return string[]
36+
*/
37+
public static function getAdditionalConfigFiles(): array
38+
{
39+
return [
40+
__DIR__ . '/../../../extension.neon',
41+
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon',
42+
];
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ImpossibleAssertMethodCall;
4+
5+
use Countable;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class Foo extends TestCase
9+
{
10+
11+
public function doFoo(Countable $c): void
12+
{
13+
$this->assertEmpty($c);
14+
$this->assertEmpty([]);
15+
$this->assertEmpty([1, 2, 3]);
16+
}
17+
18+
public function doBar(object $o): void
19+
{
20+
$this->assertEmpty($o);
21+
}
22+
23+
}

0 commit comments

Comments
 (0)