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
- Add a PHPStan rule to report an error if base test classes have metadata at class level.
- Add a test for the rule.
- 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
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:
- 3533282-ensure-base-test
changes, plain diff MR !12705
Comments
Comment #2
mondrakeI 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.
Comment #4
mondrakeChanged mind and added a PHPStan rule checking for either annotations or attributes on abstract test base classes. We have 17. errors to be solved.
Comment #5
mondrakeComment #6
smustgrave commentedCurious why did the baseline change?
Comment #7
mondrakeBecause 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.
Comment #8
smustgrave commentedOh I was just curious not that they should be fixed
Comment #9
mondrakeWell, the new rule introduces new errors, so either we fix them or we baseline them :)
Comment #10
smustgrave commentedOnly other question is should annotations be attributes or does it not matter
Comment #11
mondrakeA 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.
Comment #12
smustgrave commentedIn that case I'll go on a limb and say this one is probably ready.
Comment #13
catchCan 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.
Comment #14
mondrakeBecause 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.
Comment #15
mondrakeLet's simplify - we do not have to list all the attributes, we can just check that no attributes in the namespace
PHPUnit\Framework\Attributesare present - this also leaves space to additional attributes introduced by PHPUnit w/out needing to come back to this rule.Comment #16
mondrakeComment #17
smustgrave commentedThis probably would of been good to get in earlier, sorry it fell off my radar.
Comment #19
catchOK 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!
Comment #23
mondrake