Skip to content

Support class target for DependsOnClass attribute #5187

@iquito

Description

@iquito

All the new Depends-Attributes only support methods, not classes, which mostly makes sense to me, yet I think it would make sense to be able to target a class for the attribute #[DependsOnClass].

The main advantage I see is that PHPUnit could then skip that whole class if any assertion in the depended-on class failed, speeding up the execution of tests and making the failure output more succinct, as only the early failure is shown instead of possibly many additional failures based on the failed dependency. As far as I understand it, the same could be achieved by adding #[DependsOnClass] on all class methods, but if all test methods rely on the other class, it would be clearer to just have one #[DependsOnClass] at the top of the class.

As far as I have tested, @depends Classname::class does work on a class - all tests in the class are skipped in that case, so being able to target classes with #[DependsOnClass] would be in line with how the equivalent annotation in PHPUnit 9.x worked. After more tests, this turned out to be wrong - maybe @depends is not supported on classes and I just assumed it was, so this would be purely a new feature.

#[DependsExternal] might be an additional candidate to be able to target a class with.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions