phpstan-phpunit icon indicating copy to clipboard operation
phpstan-phpunit copied to clipboard

AssertEqualsWithCountRule?

Open gemal opened this issue 5 months ago • 1 comments

We have the AssertSameWithCountRule rule: https://github.com/phpstan/phpstan-phpunit/blob/2.0.x/src/Rules/PHPUnit/AssertSameWithCountRule.php

is there a reason for not having AssertEqualsWithCountRule

so that $this->assertEquals(45, count($actual)); would become $this->assertCount(45, $actual);

I can make a pull request I just wanted to make sure if there were a reason

gemal avatar Sep 15 '25 13:09 gemal

Well AssertEqualsIsDiscouragedRule will already pick this up and recommend assertSame call so you'll eventually get to assertCount by following this chain of reported errors 😊

Adding yet another rule would mean that you'd get two different errors for $this->assertEquals(45, count($actual));, each one recommending something different.

Of course tailoring AssertEqualsIsDiscouragedRule for $this->assertEquals(45, count($actual)); and letting it recommend assertCount directly would be useful, so feel free to contribute that.

ondrejmirtes avatar Sep 15 '25 15:09 ondrejmirtes