diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml index e6f9e763ef771e63554d1f82faca027efcaa6559..34cc413a648840100c78a8ee8ac5a6b5069944c5 100644 --- a/includes/include.drupalci.main.yml +++ b/includes/include.drupalci.main.yml @@ -1055,9 +1055,15 @@ nightwatch (next major): # Otherwise add --group $_PHPUNIT_TESTGROUPS WHAT_TO_RUN=$([[ "$_PHPUNIT_TESTGROUPS" == "" || "$_PHPUNIT_TESTGROUPS" == "--all" ]] && echo "" || echo "--group $_PHPUNIT_TESTGROUPS") PHPUNIT_OPTIONS='' - # If the project does not have its own phpunit.xml(.dist) then use the one from core. Only do this if no -c option is specified in _PHPUNIT_EXTRA. - if [[ ! $_PHPUNIT_EXTRA =~ "-c " ]]; then - test -f "$CI_PROJECT_DIR/phpunit.xml" || test -f "$CI_PROJECT_DIR/phpunit.xml.dist" || PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS -c $_WEB_ROOT/core" + # If the project does not have its own phpunit.xml(.dist) then use the one from core. Only do this if no configuration options are specified in _PHPUNIT_EXTRA. + if [[ ! -f "$CI_PROJECT_DIR/phpunit.xml" && ! -f "$CI_PROJECT_DIR/phpunit.xml.dist" && ! $_PHPUNIT_EXTRA =~ (-c |--configuration|--no-configuration) ]]; then + echo "Getting phpunit.xml.dist from $_WEB_ROOT/core" + cp $_WEB_ROOT/core/phpunit.xml.dist phpunit.xml + echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-phpunit-xml.php" + curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-phpunit-xml.php + php prepare-phpunit-xml.php + rm prepare-phpunit-xml.php + printf "$DIVIDER\n" fi printf "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA\nPHPUNIT_OPTIONS=$PHPUNIT_OPTIONS, WHAT_TO_RUN=$WHAT_TO_RUN\n" echo "executing: sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA" diff --git a/scripts/prepare-phpunit-xml.php b/scripts/prepare-phpunit-xml.php new file mode 100644 index 0000000000000000000000000000000000000000..ef23fcdd88b6d507b2bf525d66ce413c2c202c78 --- /dev/null +++ b/scripts/prepare-phpunit-xml.php @@ -0,0 +1,50 @@ +#!/usr/bin/env php +<?php + +/** + * @file + * Process the core phpunit.xml to make it suitable for contrib testing. + * + * Arguments: + * -v --verbose Show verbose debug output. + * -s --suffix {string} Additional suffix to append to the input filename + * before writing out, when testing the script locally, + * to avoid overwriting the original file. + */ + +// Get the options. +$options = getopt('s:v', ['suffix:', 'verbose']); +$quiet = !array_key_exists('v', $options) && !array_key_exists('verbose', $options); +$suffix = $options['s'] ?? $options['suffix'] ?? ''; +$quiet ?: print "quiet=$quiet\nsuffix=$suffix\n"; + +// Get the contents of the phpunit.xml file. +$phpunit_filename = 'phpunit.xml'; +if (!file_exists($phpunit_filename)) { + throw new RuntimeException("Unable to read $phpunit_filename"); +} +$xml = new DOMDocument(); +$xml->load($phpunit_filename); +$quiet ?: print_r($xml->getElementsByTagName('coverage')); +$quiet ?: print_r($xml->getElementsByTagName('source')); + +$root = $xml->documentElement; +// 'coverage' is in the Drupal 10 phpunit.xml +if ($coverage = $root->getElementsByTagName('coverage')) { + // Remove all 'coverage' as there may be more than one. + while ($coverage->length) { + $root->removeChild($coverage->item(0)); + } +} +// 'source' is the coverage definition in Drupal 11 phpunit.xml +if ($source = $root->getElementsByTagName('source')) { + while ($source->length) { + $root->removeChild($source->item(0)); + } +} +$quiet ?: print_r($xml->getElementsByTagName('coverage')); +$quiet ?: print_r($xml->getElementsByTagName('source')); + +$phpunit_filename .= $suffix; +$quiet ?: print "writing to {$phpunit_filename}\n"; +$xml->save($phpunit_filename);