You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generally speaking PHPUnit looks for tests in files named *Test.php, which conventionally means the classes should be named *Test. Additionally I believe it is recommended/required (I cannot find docs for this) that "tests" designed to be extended should be named *TestCase.
I propose adding rule to this extension which enforces that classes are named appropriately:
If a concrete class extends PHPUnit\Framework\TestCase and it should be named *Test - could also enforce final?
If an abstract class extends PHPUnit\Framework\TestCase it should be named *TestCase.
Ideally the rule would also enforce the file is named appropriately as well but that might be outside scope.
If this convention isn't followed and you don't explicitly tell PHPUnit your test files then tests are not run, potentially keeping the build passing because a number of tests are being silently ignored.
Another one: all public non-static methods should have a #[Test] attribute or named like test*. It happened a few times we thought we had tests but they were not picked up.
Activity
ruudk commentedon Nov 26, 2024
I like this idea.
ruudk commentedon Nov 26, 2024
Another one: all public non-static methods should have a
#[Test]attribute or named liketest*. It happened a few times we thought we had tests but they were not picked up.ruudk commentedon Nov 26, 2024
This could be a good starting point for the final / abstract part, or as inspiration: https://github.com/ergebnis/phpstan-rules/blob/main/src/Classes/FinalRule.php
cs278 commentedon Nov 27, 2024
@ruudk I've thrown a PR together implementing my proposal, your proposal for checking methods as well could be added as an additional rule.
staabm commentedon Dec 10, 2024
since I also stumbled recently over the "name your abstract test class" with a "TestCase" suffix, I really like this proposal.
ondrejmirtes commentedon Dec 10, 2024
Hey, this isn't generally applicable. The way PHPUnit looks for test files is configurable. It's just that it usually looks like this:
I feel like these suggested rules are too opinionated for the general audience.
cs278 commentedon Dec 16, 2024
Damn, I'd completely forgotten this was even configurable.
github-actions commentedon Jan 17, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.