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

[Rule Idea]: Validate Correct Test Class Usage Based on Inherited Methods #429

Closed
santysisi opened this issue Feb 26, 2025 · 3 comments
Closed

Comments

@santysisi
Copy link

Hello,

I've been working on a custom PHPStan rule for my team to validate the correct usage of test classes. This rule checks if a test class is using any methods from its immediate parent class. If not, it suggests inheriting from a more appropriate parent class.

Specifically, it validates test classes that extend:

For example, if a test class extends Symfony\Bundle\FrameworkBundle\Test\KernelTestCase but doesn't use any of its methods, the rule would report an error and suggest trying PHPUnit\Framework\TestCase instead.

We implemented this rule because in our large team, many developers were writing tests that weren't optimally structured, leading to slower pipeline execution. This rule helps ensure tests are written using the most efficient base class.

If this idea aligns with the project's goals, I'd be happy to refine the code of my custom rule and submit a pull request to phpstan-symfony, potentially for the 2.1.0 release.

Thank you for your consideration.

@ruudk
Copy link
Contributor

ruudk commented Feb 27, 2025

Interesting idea! I like it. I feel like this should belong to phpstan-phpunit.

@ondrejmirtes
Copy link
Member

This is a good idea but not a good fit for phpstan-symfony or phpstan-phpunit.

It's not a bug to extend a class you don't need. So this is very opinionated.

Feel free to implement it and publish as your own package.

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants