Problem/Motivation
Test::parseTestMethodAnnotations is removed from PHPUnit 10. Needs finding an alternative for
Drupal\Tests\migrate\Kernel\MigrateSourceTestBase
Drupal\BuildTests\Framework\ExternalCommandRequirementsTrait
Drupal\Tests\TestRequirementsTrait
that rely on it.
Done
- #3362083: '@requires externalCommand' is not parsed in PHPUnit 10
- #3418379: Deprecate Drupal\Tests\TestRequirementsTrait::checkRequirements and ::checkModuleRequirements
Proposed resolution
Introduce a light ::getTestClassCovers() shim in the PhpUnit TestCompatibilityTrait that abstracts fetching the @cover annotations via Test::parseTestMethodAnnotations() in PHPUnit 9; when shifting to PHPUnit 10 change the implementation to the new $this->valueObjectForEvents()->metadata()->isCovers() methods (see prototype in https://git.drupalcode.org/project/drupal/-/blame/904e0e97f562e88b06dcf0...)
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3355795
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:
- 3355795-pp-1-testparsetestmethodannotations-is
changes, plain diff MR !6409
Comments
Comment #2
mondrakeComment #4
mondrakeComment #5
mondrakeComment #6
gábor hojtsyComment #7
mondrakeBetter do this once #3405353: Convert use of TestCase::getName() to forward compatible TestCase::name() is in, that revives the PhpUnitCompatibilityTrait.
Comment #9
mondrakeComment #10
mondrakeComment #11
mondrakeComment #12
mondrakeComment #13
mondrakeComment #14
mondrakeComment #15
smustgrave commentedSearched for parseTestMethodAnnotations and found TestRequirementsTrait but that appears to be testing the deprecation of parseTestMethodAnnotations.
Other instance is replaced here.
LGTM
Comment #16
spokjePondered about this being nowadays a "misuse" of the
@covers-tag (although currently nifty and when implemented probably The-Only-Way) and if this should have a follow-up to make this into a whole new annotation.I'm unsure, maybe core committers have an idea about this?
No matter what, this has to get in asap to get use closer to the PHPUnit 10 hurdle.
Comment #17
longwaveI think we can defer that decision until the PHPUnit 10 upgrade. It seems a relatively neat way of doing it, we need metadata about which class we are testing and conveniently we can borrow that from PHPUnit already. As long as the PHPUnit 10 metadata method handles both attributes and annotations then I don't see an issue, and we should be able to upgrade to PHPUnit 10 first and then migrate test annotations to attributes separately if we need to.
Committed 0e38c5f and pushed to 11.x. Thanks!
Comment #20
smustgrave commentedUpdating attribution
Comment #21
mondrakeThis https://git.drupalcode.org/project/drupal/-/blob/6ba264f34cc45511333ef47... is how the trait will change to support PHPUnit 10.
PHPUnit 10 will support both. PHPUnit 11 will deprecate annotations. PHPUnit 12 will remove them. We potentially need to convert annotations to attributes before Drupal 11 if we want to target PHPUnit 11 for it AND we do not want deprecation notices.