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.

Proposed resolution

  • Add an additional --phpunit-configuration argument for run-tests.sh, adjust GitLabCI scripts to add a variable holding PHPUnit configuration file path and using it when executing run-tests.sh.
  • Copy current phpunit.xml.dist configuration file to a file named .phpunit-10.xml so that tests that need to run with PHPUnit 10 can reference that file
  • Edit phpunit.xml.dist configuration file to remove duplicate directories that are generating test discovery warnings under PHPUnit 11
  • Dropped the earlier .phpunit-next.xml file and made performance test point to the main core PHPUnit configuration now that it's PHPUnit 11 fully compliant.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#11 3530113-nr-bot.txt91 bytesneeds-review-queue-bot

Issue fork drupal-3530113

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

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
mondrake’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

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.

jonathan1055’s picture

@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?

mondrake’s picture

#6 would be great!! Thanks in advance

smustgrave’s picture

Yea that would be cool to see!

jonathan1055’s picture

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.

mondrake’s picture

@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.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

rebased

mondrake’s picture

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

I will rebase the MR

mondrake’s picture

Assigned: mondrake » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

catch’s picture

Status: Reviewed & tested by the community » Needs review

One question on the MR.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
jonathan1055’s picture

Thanks for the hint @mondrake re #9 - #10. I have now sucessfully used this MR in a contrib pipeline. In my custom.xml I defined <testsuite name="only-default-time"> then added --types only-default-time --all --phpunit-configuration $PHPUNIT_CONFIGURATION_FILE_PATH and also PHPUNIT_CONFIGURATION_FILE_PATH: $CI_PROJECT_DIR/custom.xml in .gitlab-ci.yml and the specified subset of tests was run. This demonstrates that my specified custom.xml config must be active and that therefore we can use this mechanism in Gitlab Templates for Contib pipelines too.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This looks good to me but I agree with #5 that it could use a CR (could have been moved to needs work for that instead of RTBC).

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

Added draft CR

catch’s picture

Status: Reviewed & tested by the community » Fixed

This looks good to me, should make it easier long term for phpunit 12 etc.

Committed/pushed to 11.x, thanks!

  • catch committed 8ad7502b on 11.x
    Issue #3530113 by mondrake, jonathan1055: Allow indicating alternative...

Status: Fixed » Closed (fixed)

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