diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 94ec4414dbe..4233e88066c 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -490,18 +490,16 @@ class phpunit_util extends testing_util { public static function build_config_file() { global $CFG; - $template = ' - - @dir@ - '; - $filtertemplate = ' - - @dir@ - '; + $template = << + @dir@ + + + EOF; $data = file_get_contents("$CFG->dirroot/phpunit.xml.dist"); $suites = ''; - $whitelists = []; + $includelists = []; $excludelists = []; $subsystems = core_component::get_core_subsystems(); @@ -517,7 +515,7 @@ class phpunit_util extends testing_util { $dir = substr($fulldir, strlen($CFG->dirroot) + 1); if ($coverageinfo = self::get_coverage_info($fulldir)) { - $whitelists = array_merge($whitelists, $coverageinfo->get_whitelists($dir)); + $includelists = array_merge($includelists, $coverageinfo->get_includelists($dir)); $excludelists = array_merge($excludelists, $coverageinfo->get_excludelists($dir)); } } @@ -544,7 +542,7 @@ class phpunit_util extends testing_util { if ($coverageinfo = self::get_coverage_info($plugindir)) { - $whitelists = array_merge($whitelists, $coverageinfo->get_whitelists($dir)); + $includelists = array_merge($includelists, $coverageinfo->get_includelists($dir)); $excludelists = array_merge($excludelists, $coverageinfo->get_excludelists($dir)); } } @@ -555,14 +553,14 @@ class phpunit_util extends testing_util { // end up being placed in phpunit or behat test code. $sequencestart = 100000 + mt_rand(0, 99) * 1000; - $data = preg_replace('|.*|s', $suites, $data, 1); + $data = preg_replace('| *.*|s', trim($suites, "\n"), $data, 1); $data = str_replace( '', '', $data); - $filters = self::get_filter_config($whitelists, $excludelists); - $data = str_replace('', $filters, $data); + $coverages = self::get_coverage_config($includelists, $excludelists); + $data = preg_replace('| *|s', trim($coverages, "\n"), $data); $result = false; if (is_writable($CFG->dirroot)) { @@ -583,19 +581,21 @@ class phpunit_util extends testing_util { public static function build_component_config_files() { global $CFG; - $template = ' - - - . - - '; - $filterdefault = ' - - . - - . - - '; + $template = << + + . + + + EOT; + $coveragedefault = << + . + + + . + + EOT; // Start a sequence between 100000 and 199000 to ensure each call to init produces // different ids in the database. This reduces the risk that hard coded values will @@ -604,7 +604,7 @@ class phpunit_util extends testing_util { // Use the upstream file as source for the distributed configurations $ftemplate = file_get_contents("$CFG->dirroot/phpunit.xml.dist"); - $ftemplate = preg_replace('|', $ftemplate); + $ftemplate = preg_replace('| *', $ftemplate); // Gets all the components with tests $components = tests_finder::get_components_with_tests('phpunit'); @@ -617,13 +617,13 @@ class phpunit_util extends testing_util { $fcontents = str_replace('', $ctemplate, $ftemplate); - // Check for filter configurations. + // Check for coverage configurations. if ($coverageinfo = self::get_coverage_info($cpath)) { - $filters = self::get_filter_config($coverageinfo->get_whitelists(''), $coverageinfo->get_excludelists('')); + $coverages = self::get_coverage_config($coverageinfo->get_includelists(''), $coverageinfo->get_excludelists('')); } else { - $filters = $filterdefault; + $coverages = $coveragedefault; } - $fcontents = str_replace('', $filters, $fcontents); + $fcontents = preg_replace('| *|s', trim($coverages, "\n"), $fcontents); // Apply it to the file template. $fcontents = str_replace( @@ -931,34 +931,34 @@ class phpunit_util extends testing_util { * @return string */ protected static function pad(string $string, int $level) : string { - return str_repeat(" ", $level * 4) . "{$string}\n"; + return str_repeat(" ", $level * 2) . "{$string}\n"; } /** - * Get the filter config for the supplied whitelist and excludelist configuration. + * Get the coverage config for the supplied includelist and excludelist configuration. * - * @param array[] $whitelists The list of files/folders in the whitelist. + * @param array[] $includelists The list of files/folders in the includelist. * @param array[] $excludelists The list of files/folders in the excludelist. * @return string */ - protected static function get_filter_config(array $whitelists, array $excludelists) : string { - $filters = ''; - if (!empty($whitelists)) { - $filters .= self::pad("", 2); - foreach ($whitelists as $line) { - $filters .= self::pad($line, 3); + protected static function get_coverage_config(array $includelists, array $excludelists) : string { + $coverages = ''; + if (!empty($includelists)) { + $coverages .= self::pad("", 2); + foreach ($includelists as $line) { + $coverages .= self::pad($line, 3); } + $coverages .= self::pad("", 2); if (!empty($excludelists)) { - $filters .= self::pad("", 3); + $coverages .= self::pad("", 2); foreach ($excludelists as $line) { - $filters .= self::pad($line, 4); + $coverages .= self::pad($line, 3); } - $filters .= self::pad("", 3); + $coverages .= self::pad("", 2); } - $filters .= self::pad("", 2); } - return $filters; + return $coverages; } /**