Skip to content

Commit

Permalink
Support assertNotEquals in AssertEqualsIsDiscouragedRule
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Dec 19, 2024
1 parent 2cedfb7 commit e32ac65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Rules/PHPUnit/AssertEqualsIsDiscouragedRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\TypeCombinator;
use function count;
use function in_array;
use function strtolower;

/**
Expand All @@ -32,7 +33,10 @@ public function processNode(Node $node, Scope $scope): array
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || strtolower($node->name->name) !== 'assertequals') {
if (
!$node->name instanceof Node\Identifier
|| !in_array(strtolower($node->name->name), ['assertequals', 'assertnotequals'], true)
) {
return [];
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Rules/PHPUnit/AssertEqualsIsDiscouragedRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function testRule(): void
[self::ERROR_MESSAGE, 29],
[self::ERROR_MESSAGE, 30],
[self::ERROR_MESSAGE, 32],
[self::ERROR_MESSAGE, 37],
[self::ERROR_MESSAGE, 38],
[self::ERROR_MESSAGE, 39],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Rules/PHPUnit/data/assert-equals-is-discouraged.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public function dummyTest(string $string, int $integer, bool $boolean, float $fl
$this->assertEquals([], []);
$this->assertEquals(new Exception(), new Exception());
static::assertEquals(new Exception(), new Exception());

$this->assertNotEquals($string, $string);
$this->assertNotEquals($integer, $integer);
$this->assertNotEquals($boolean, $boolean);
$this->assertNotSame(5, $integer);
static::assertNotSame(5, $integer);
}
}

0 comments on commit e32ac65

Please sign in to comment.