Skip to content

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

@santysisi

Description

@santysisi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions