Problem/Motivation
@requires module xxxxx is not a supported syntax in PHPUnit 10, and its parser no longer processes it.
The valid types of @requires are described here, https://docs.phpunit.de/en/10.5/annotations.html#requires
We can no longer rely on PHPUnit internal Test::parseTestMethodAnnotations() method (which is no longer existing BTW), nor on its new Metadata API, to fetch this information.
Steps to reproduce
Apparently the only test using @requires module xxxx is Drupal\Tests\jsonapi\Functional\FileUploadTest, but there are references to it in KernelTestBase and in some fixtures.
Proposed resolution
tbd
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3418379
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:
- 3418379-requires-module-xxxx
changes, plain diff MR !6412
Comments
Comment #3
mondrakeOne proposal could be to replace the annotation
@requires module xxxxwith an attribute, say#[RequiresDrupalModules(['xxxx']), and usual deprecation dance.However, there only are 3 tests using this feature:
Two are to test the feature itself, and for the third (FileUploadTest) the check is actually not even triggered, not sure why - but in any case it can be replaced with a simple
markTestSkipped.So not sure - is it something we need to keep supporting, or can we get rid of it altogether?
Comment #4
longwaveThis has been broken for some time, see #3261817: TestRequirementsTrait::checkRequirements() does not work as expected
Comment #5
mondrakeWell two years not working means no one needs it. I propose to deprecate for removal.
Comment #6
spokjeValid point IMHO, deprecation dance++
Comment #7
mondrakeComment #8
smustgrave commentedDeprecation seems good and has test coverage.
Comment #9
mondrakeMore accurate title.
Comment #10
mondrakeUpdated CR
Comment #11
spokjeAfter a night sleep (I know, I shouldn't do that...), I'm a bit worried to drop this functionality.
Core doesn't use it, that's clear by now, and it's broken, but contrib uses it (a lot): http://codcontrib.hank.vps-private.net/search?text=%40requires%20module&...
Not sure if since it's not working, fixing it/replacing it with an annotation could/would mean contrib tests will break, or is this long superseded by adding the modules-on-which-to-depend in the
require-devsection of the modulescomposer.jsonand is this also dead code in contrib?Comment #12
mondrakeThis has probably been broken for 4 years now, since when #2950132: Support PHPUnit 7 optionally in Drupal 8, while keeping support for ^6.5 was committed.
Personally in the contrib modules I maintain I add the test required modules in the require-dev of the composer.json file. In fact it’s a must have if you want the CI tools to install them.
Comment #13
longwaveGiven there was little activity over in #3261817: TestRequirementsTrait::checkRequirements() does not work as expected I also suspect this has been broken since then but nobody in contrib land has noticed, so to me that means it's not worth maintaining (or in this case, refactoring for PHPUnit 10), and so I agree this should be deprecated for removal.
Comment #14
spokje(Emphasis mine)
Thanks, there we have it, kill it with fire!
Comment #15
longwaveWe should have a followup though to clean up FileUploadTest, as those are six test methods that we should skip entirely if we can.
Comment #16
mondrakeI think better to that here, it’s an unusual deprecation and leving things around won’t be good. Thre’s a comment somewhere, too.
Comment #17
mondrakeDone.
Comment #18
spokjeClean up makes sense, nice catch in
core/tests/Drupal/KernelTests/KernelTestBase.phpComment #19
quietone commentedThe wiki has a reference to using
@requires modulethat should be removed.https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/phpunit-...
Comment #20
spokjeThanks @quietone, removed section from the wiki page.
Comment #22
longwaveCommitted 614ff9d and pushed to 11.x. Thanks!
Also published the change record.