Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 26, 2022
1 parent 6b93db7 commit a0c1364
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/Rules/PHPUnit/ImpossibleCheckTypeMethodCallRuleTest.php
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 tests/Rules/PHPUnit/data/impossible-assert-method-call.php
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);
}

}

0 comments on commit a0c1364

Please sign in to comment.