mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-37783 add some useful information to any phpunit output
This commit is contained in:
parent
373a8e052c
commit
15bac12e9d
@ -212,6 +212,8 @@ if (PHPUNIT_UTIL) {
|
||||
|
||||
// is database and dataroot ready for testing?
|
||||
list($errorcode, $message) = phpunit_util::testing_ready_problem();
|
||||
// print some version info
|
||||
phpunit_util::bootstrap_moodle_info();
|
||||
if ($errorcode) {
|
||||
phpunit_bootstrap_error($errorcode, $message);
|
||||
}
|
||||
|
@ -235,6 +235,72 @@ class phpunit_util extends testing_util {
|
||||
phpunit_util::reset_all_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print some Moodle related info to console.
|
||||
* @internal
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
public static function bootstrap_moodle_info() {
|
||||
global $CFG;
|
||||
|
||||
// All developers have to understand English, do not localise!
|
||||
|
||||
$release = null;
|
||||
require("$CFG->dirroot/version.php");
|
||||
|
||||
echo "Moodle $release, $CFG->dbtype";
|
||||
if ($hash = self::get_git_hash()) {
|
||||
echo ", $hash";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get current git hash of the Moodle in $CFG->dirroot.
|
||||
* @return string null if unknown, sha1 hash if known
|
||||
*/
|
||||
public static function get_git_hash() {
|
||||
global $CFG;
|
||||
|
||||
// This is a bit naive, but it should mostly work for all platforms.
|
||||
|
||||
if (!file_exists("$CFG->dirroot/.git/HEAD")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ref = file_get_contents("$CFG->dirroot/.git/HEAD");
|
||||
if ($ref === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ref = trim($ref);
|
||||
|
||||
if (strpos($ref, 'ref: ') !== 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ref = substr($ref, 5);
|
||||
|
||||
if (!file_exists("$CFG->dirroot/.git/$ref")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hash = file_get_contents("$CFG->dirroot/.git/$ref");
|
||||
|
||||
if ($hash === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hash = trim($hash);
|
||||
|
||||
if (strlen($hash) != 40) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns original state of global variable.
|
||||
* @static
|
||||
|
Loading…
x
Reference in New Issue
Block a user