Skip to content
Snippets Groups Projects
Commit 61563ab8 authored by Jonathan Smith's avatar Jonathan Smith Committed by Fran Garcia-Linares
Browse files

Issue #3486466 by jonathan1055, fjgarlin, cmlara: Adjust Core phpunit.xml to...

Issue #3486466 by jonathan1055, fjgarlin, cmlara: Adjust Core phpunit.xml to make it work for Contrib
parent 89e3dca3
No related branches found
No related tags found
1 merge request!286#3486466 Adjust core phpunit xml
Pipeline #337682 passed
......@@ -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"
......
#!/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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment