★ wanayoo — archive 1999 https://github.com/phpstan/phpstan-phpunit/issues/7Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for additional strict rules #7

Open
mhujer opened this issue Dec 28, 2017 · 5 comments
Open

Ideas for additional strict rules #7

mhujer opened this issue Dec 28, 2017 · 5 comments

Comments

@mhujer
Copy link
Contributor

@mhujer mhujer commented Dec 28, 2017

Here is a list of a ideas that may be implemented in the future:

  • suggest assertInstanceOf(Foo::class, $a) instead of assertTrue($a instanceof Foo)
  • suggest assertNotInstanceOf(Foo::class, $a) instead of assertFalse($a instanceof Foo)
  • suggest assertArrayHasKey() instead of assertTrue(array_key_exists(..))
  • suggest assertFileExists() instead of assertTrue(file_exists($filePath))
@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Dec 28, 2017

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?

@mhujer
Copy link
Contributor Author

@mhujer mhujer commented Dec 28, 2017

Suggestions for specific rules instead of assertEquals should be handled by #6.

  1. If both operands are boolean/string/integer, it would recommend using assertSame
  2. And then the other rule would suggest changing it to a more specific assert 😄
@carusogabriel
Copy link
Contributor

@carusogabriel carusogabriel commented Dec 30, 2017

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))
@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Dec 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.