Problem/Motivation

Follow-up from #3530154: Fix test classes with no *Test suffix - we found various base classes in core that had phpunit annotations that won't do anything, we should check if there are more.

Proposed resolution

  1. Add a PHPStan rule to report an error if base test classes have metadata at class level.
  2. Add a test for the rule.
  3. Baseline the errors of the current tests.

Fixing the errors is left to follow-ups.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3533282

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

mondrake’s picture

Title: Ensure base test classes don't have phpunit annotations » Ensure base test classes don't have phpunit attributes
Status: Active » Postponed

I suggest to wait for conversions of annotations to attributes to be completed, then check on attributes instead. Probably a PHPStan rule should be written here.

mondrake’s picture

Status: Postponed » Needs review

Changed mind and added a PHPStan rule checking for either annotations or attributes on abstract test base classes. We have 17. errors to be solved.

mondrake’s picture

Title: Ensure base test classes don't have phpunit attributes » Ensure base test classes don't have class level phpunit metadata
Issue summary: View changes
smustgrave’s picture

Curious why did the baseline change?

mondrake’s picture

Because fixing the errors that this rule surfaces is not trivial. So better leave that to follow ups IMHO, while the rule prevents adding more leaks.

smustgrave’s picture

Oh I was just curious not that they should be fixed

mondrake’s picture

Well, the new rule introduces new errors, so either we fix them or we baseline them :)

smustgrave’s picture

Only other question is should annotations be attributes or does it not matter

mondrake’s picture

A check to prevent the use of annotation is already done by PHPUnit itself when it is configured to fail on PHPUnit deprecations. See #3534156: Complete test annotations to attributes conversion for Drupal/Test/Component for an example.

IMHO we should not replicate such a check here.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

In that case I'll go on a limb and say this one is probably ready.

catch’s picture

Because fixing the errors that this rule surfaces is not trivial.

Can you explain why this isn't trivial? I would have thought it would only be necessary to delete the annotations from the base classes and nothing else.

mondrake’s picture

Because I think we should check if the extending classes have the metadata implemented as the base class, and if not see why not and possibly convert to attributes.

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Reviewed & tested by the community » Needs work

Let's simplify - we do not have to list all the attributes, we can just check that no attributes in the namespace PHPUnit\Framework\Attributes are present - this also leaves space to additional attributes introduced by PHPUnit w/out needing to come back to this rule.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This probably would of been good to get in earlier, sorry it fell off my radar.

  • catch committed 25057c56 on 11.x
    Issue #3533282 by mondrake: Ensure base test classes don't have class...
catch’s picture

Status: Reviewed & tested by the community » Fixed

OK let's get this one in - will mean rebasing the issues fixing the baseline but can't be helped.

Committed/pushed to 11.x, thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mondrake’s picture

Issue tags: +PHPUnit 11