-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b93db7
commit a0c1364
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
tests/Rules/PHPUnit/ImpossibleCheckTypeMethodCallRuleTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\PHPUnit; | ||
|
||
use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<ImpossibleCheckTypeMethodCallRule> | ||
*/ | ||
class ImpossibleCheckTypeMethodCallRuleTest extends RuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return self::getContainer()->getByType(ImpossibleCheckTypeMethodCallRule::class); | ||
} | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/impossible-assert-method-call.php'], [ | ||
[ | ||
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{} will always evaluate to true.', | ||
14, | ||
], | ||
[ | ||
'Call to method PHPUnit\Framework\Assert::assertEmpty() with array{1, 2, 3} will always evaluate to false.', | ||
15, | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../../extension.neon', | ||
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon', | ||
]; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
tests/Rules/PHPUnit/data/impossible-assert-method-call.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace ImpossibleAssertMethodCall; | ||
|
||
use Countable; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Foo extends TestCase | ||
{ | ||
|
||
public function doFoo(Countable $c): void | ||
{ | ||
$this->assertEmpty($c); | ||
$this->assertEmpty([]); | ||
$this->assertEmpty([1, 2, 3]); | ||
} | ||
|
||
public function doBar(object $o): void | ||
{ | ||
$this->assertEmpty($o); | ||
} | ||
|
||
} |