phpstan-phpunit
phpstan-phpunit copied to clipboard
Ideas for additional strict rules
Here is a list of a ideas that may be implemented in the future:
- [ ] suggest
assertInstanceOf(Foo::class, $a)
instead ofassertTrue($a instanceof Foo)
- [ ] suggest
assertNotInstanceOf(Foo::class, $a)
instead ofassertFalse($a instanceof Foo)
- [ ] suggest
assertArrayHasKey()
instead ofassertTrue(array_key_exists(..))
- [ ] suggest
assertFileExists()
instead ofassertTrue(file_exists($filePath))
I think that assertArrayHasKey
and assertFileExists
are not that common and can be written in multiple ways, so I'm not sure about them.
BTW: It might be interesting to suggest assertCount and other already implemented rules also for assertEquals
and not just assertSame
. I know that it's a loose comparison but those more-specific asserts might also be loose comparisons as well?
Suggestions for specific rules instead of assertEquals
should be handled by https://github.com/phpstan/phpstan-phpunit/pull/6.
- If both operands are boolean/string/integer, it would recommend using
assertSame
- And then the other rule would suggest changing it to a more specific assert 😄
I have more suggestions, and if I could help implement them :smile_cat: :
- [ ] Suggest
assertCount(1, $foo)
instead ofassertSame(1, sizeof($foo))
- [ ] Suggest
assertContains('foo', [...])
instead ofassertTrue(in_array('foo', [...]))
- [ ] Suggest
assertEmpty($foo)
instead ofassertTrue(empty($foo))
Go for it 😊
On Sat, 30 Dec 2017 at 22:03, Gabriel Caruso [email protected] wrote:
I have more suggestions, and if I could help implement them 😸 :
- Suggest assertCount(1, $foo) instead of assertSame(1, sizeof($foo))
- Suggest assertContains('foo', [...]) instead of assertTrue(in_array('foo', [...]))
- Suggest assertEmpty($foo) instead of assertTrue(empty($foo))
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan-phpunit/issues/7#issuecomment-354568210, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuFsRghGOxp9uhDRItjYVN_z_i1_hks5tFqUDgaJpZM4ROcPW .
--
Ondřej Mirtes
More ideas https://docs.google.com/spreadsheets/d/145hef6esG-B09AfooY-4e0oFKa1eVDoeUeo-eXVZRoA/edit?usp=sharing...