Allow indicating alternative phpunit.xml than core's when testing via run-tests.sh

Created on 13 June 2025, 10 days ago

Problem/Motivation

run-tests.sh hardcodes using core's phpunit.xml.dist file when invoking PHPUnit subprocesses.

It would be good to allow passing in alternative (e.g. module specific) xml configuration files to allow tailoring test execution behaviour, as this seems to be becoming more and more a need as PHPUnit evolves.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

phpunit

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mondrake
  • @mondrake opened merge request.
  • 🇮🇹Italy mondrake 🇮🇹
  • 🇮🇹Italy mondrake 🇮🇹
  • 🇺🇸United States smustgrave

    Seems pretty straight forward, didn't seem to break gitlab :). Not sure if this kind of change needs a CR but addition of --phpunit-configuration seems fine to me.

  • 🇬🇧United Kingdom jonathan1055

    @mondrake and @smustgrave, Would you like me to use this patch in a Contrib pipeline to try it and see if I can use an alternative phpunit.xml when runing phpunif with run-tests.sh?

  • 🇮🇹Italy mondrake 🇮🇹

    #6 would be great!! Thanks in advance

  • 🇺🇸United States smustgrave

    Yea that would be cool to see!

  • 🇬🇧United Kingdom jonathan1055

    I have the mechanics of this working now in Scheduler MR194. The patch has to be allowed to fail because the two .gitlab files are not present, but that does not matter, the other two files are patched OK. I have added a custom phpunit config, called custom.xml just to make sure we can tell it is distinct. I have defined a testsuite in it, but using --testsuite gives ERROR: Unknown argument '--testsuite' as that is not a recognised parameter in run-tests.sh
    https://git.drupalcode.org/project/scheduler/-/jobs/5637581

    I then tried just using the name of the testsuite, which is 'only-token-test' and that gives ERROR: Test group not found: only-token-test because of course the default type of filter is on test group, not test suite.
    https://git.drupalcode.org/project/scheduler/-/jobs/5637673

    Do you have other suggestions on how I can verify that this config is active? If I pass in --module, --class or --file then those arguments will take precedence.

  • 🇮🇹Italy mondrake 🇮🇹

    @jonathan1055 the way core executes individual PHPUnit testsuites is via run-tests.sh --types "$TESTSUITE" --all arguments.

    But there is a BUT: there's a difference between the way testsuites are indicated in the .gitlab-ci.yml file and how they're defined in the phpunit.xml.dist testsuites section. run-tests.sh manages on the fly the conversion between e.g. PHPUnit-Unit (in GitLab CI) and unit (in phpunit.xml) and viceversa.

    I do not remember what would happen if the --types "$TESTSUITE" --all has a $TESTSUITE value which is not one of the core phpunit's testsuites. Worth checking it, and if it fails, fix here to let fallback the conversion to the input value.

    I think it would be worth deprecating --types and --all arguments and introduce sth along the lines of --phpunit-testsuite and --phpunit-group to match PHPUnit's --testsuite and --group arguments, but IMHO should be part of a follow-up issue.

Production build 0.71.5 2024