mirror of
https://github.com/moodle/moodle.git
synced 2025-06-02 06:05:31 +02:00
MDL-32587 improve component phpunit config building and make the util.php help fit 80char screens
This commit is contained in:
parent
cb48174266
commit
8e5c963e6b
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,4 +25,4 @@ CVS
|
||||
/.project
|
||||
/.buildpath
|
||||
/.cache
|
||||
/phpunit.xml
|
||||
phpunit.xml
|
@ -34,14 +34,14 @@ require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
|
||||
// now get cli options
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'drop' => false,
|
||||
'install' => false,
|
||||
'buildconfig' => false,
|
||||
'buildconfigdist' => false,
|
||||
'diag' => false,
|
||||
'phpunitdir' => false,
|
||||
'run' => false,
|
||||
'help' => false,
|
||||
'drop' => false,
|
||||
'install' => false,
|
||||
'buildconfig' => false,
|
||||
'buildcomponentconfigs' => false,
|
||||
'diag' => false,
|
||||
'phpunitdir' => false,
|
||||
'run' => false,
|
||||
'help' => false,
|
||||
),
|
||||
array(
|
||||
'h' => 'help'
|
||||
@ -106,20 +106,21 @@ $diag = $options['diag'];
|
||||
$drop = $options['drop'];
|
||||
$install = $options['install'];
|
||||
$buildconfig = $options['buildconfig'];
|
||||
$buildconfigdist = $options['buildconfigdist'];
|
||||
$buildcomponentconfigs = $options['buildcomponentconfigs'];
|
||||
|
||||
if ($options['help'] or (!$drop and !$install and !$buildconfig and !$buildconfigdist and !$diag)) {
|
||||
if ($options['help'] or (!$drop and !$install and !$buildconfig and !$buildcomponentconfigs and !$diag)) {
|
||||
$help = "Various PHPUnit utility functions
|
||||
|
||||
Options:
|
||||
--drop Drop database and dataroot
|
||||
--install Install database
|
||||
--buildconfig Build /phpunit.xml from /phpunit.xml.dist that includes suites for all plugins and core
|
||||
--buildconfigdist Build distributed phpunit.xml files for each plugin and subsystem
|
||||
--diag Diagnose installation and return error code only
|
||||
--run Execute PHPUnit tests (alternative for standard phpunit binary)
|
||||
--drop Drop database and dataroot
|
||||
--install Install database
|
||||
--diag Diagnose installation and return error code only
|
||||
--run Execute PHPUnit tests (alternative for standard phpunit binary)
|
||||
--buildconfig Build /phpunit.xml from /phpunit.xml.dist that runs all tests
|
||||
--buildcomponentconfigs
|
||||
Build distributed phpunit.xml files for each component
|
||||
|
||||
-h, --help Print out this help
|
||||
-h, --help Print out this help
|
||||
|
||||
Example:
|
||||
\$/usr/bin/php lib/phpunit/tool.php --install
|
||||
@ -139,15 +140,12 @@ if ($diag) {
|
||||
if (phpunit_util::build_config_file()) {
|
||||
exit(0);
|
||||
} else {
|
||||
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, 'Can not create main phpunit.xml configuration file, verify dirroot permissions');
|
||||
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, 'Can not create main /phpunit.xml configuration file, verify dirroot permissions');
|
||||
}
|
||||
|
||||
} else if ($buildconfigdist) {
|
||||
if (phpunit_util::build_distributed_config_files()) {
|
||||
exit(0);
|
||||
} else {
|
||||
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, 'Can not create main phpunit.xml configuration file, verify dirroot permissions');
|
||||
}
|
||||
} else if ($buildcomponentconfigs) {
|
||||
phpunit_util::build_component_config_files();
|
||||
exit(0);
|
||||
|
||||
} else if ($drop) {
|
||||
// make sure tests do not run in parallel
|
||||
|
@ -888,24 +888,23 @@ class phpunit_util {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds distributed phpunit.xml and dataroot/phpunit/webrunner.xml files using defaults from /phpunit.xml.dist
|
||||
* Builds phpunit.xml files for all components using defaults from /phpunit.xml.dist
|
||||
*
|
||||
* @static
|
||||
* @return bool true means all config files created, false means only dataroot file created
|
||||
* @return void, stops if can not write files
|
||||
*/
|
||||
public static function build_distributed_config_files() {
|
||||
public static function build_component_config_files() {
|
||||
global $CFG;
|
||||
|
||||
$template = '
|
||||
<testsuites>
|
||||
<testsuite name="@component@">
|
||||
<directory suffix="_test.php">@dir@</directory>
|
||||
<directory suffix="_test.php">.</directory>
|
||||
</testsuite>
|
||||
</testsuites>';
|
||||
|
||||
// Use the upstream file as source for the distributed configurations
|
||||
$ftemplate = file_get_contents("$CFG->dirroot/phpunit.xml.dist");
|
||||
$ftemplate = preg_replace('|lib/phpunit/bootstrap.php|', $CFG->dirroot . '/lib/phpunit/bootstrap.php', $ftemplate);
|
||||
$ftemplate = preg_replace('|<!--All core suites.*</testsuites>|s', '<!--@component_suite@-->', $ftemplate);
|
||||
|
||||
// Get all the components
|
||||
@ -925,11 +924,15 @@ class phpunit_util {
|
||||
// Calculate the component suite
|
||||
$ctemplate = $template;
|
||||
$ctemplate = str_replace('@component@', $cname, $ctemplate);
|
||||
$ctemplate = str_replace('@dir@', $cpath, $ctemplate);
|
||||
|
||||
// Apply it to the file template
|
||||
$fcontents = str_replace('<!--@component_suite@-->', $ctemplate, $ftemplate);
|
||||
|
||||
// fix link to schema
|
||||
$level = substr_count(str_replace('\\', '/', $cpath), '/') - substr_count(str_replace('\\', '/', $CFG->dirroot), '/');
|
||||
$fcontents = str_replace('lib/phpunit/phpunit.xsd', str_repeat('../', $level).'lib/phpunit/phpunit.xsd', $fcontents);
|
||||
$fcontents = str_replace('lib/phpunit/bootstrap.php', str_repeat('../', $level).'lib/phpunit/bootstrap.php', $fcontents);
|
||||
|
||||
// Write the file
|
||||
$result = false;
|
||||
if (is_writable($cpath)) {
|
||||
@ -942,15 +945,12 @@ class phpunit_util {
|
||||
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, "Can not create $cpath/phpunit.xml configuration file, verify dir permissions");
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, build the main config file too
|
||||
return self::build_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the plugins having phpunit tests
|
||||
* Returns all the plugins having PHPUnit tests
|
||||
*
|
||||
* @return array all the plugins having phpunit tests
|
||||
* @return array all the plugins having PHPUnit tests
|
||||
*
|
||||
*/
|
||||
private static function get_all_plugins_with_tests() {
|
||||
@ -972,13 +972,13 @@ class phpunit_util {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the subsystems having phpunit tests
|
||||
* Returns all the subsystems having PHPUnit tests
|
||||
*
|
||||
* Note we are hacking here the list of subsystems
|
||||
* to cover some well-known subsystems that are not properly
|
||||
* returned by the {@link get_core_subsystems()} function.
|
||||
*
|
||||
* @return array all the subsystems having phpunit tests
|
||||
* @return array all the subsystems having PHPUnit tests
|
||||
*/
|
||||
private static function get_all_subsystems_with_tests() {
|
||||
global $CFG;
|
||||
|
Loading…
x
Reference in New Issue
Block a user