MDL-33557 fix path in PHPUnit init hint

This resolves problem when execution phpunit in subdirectory.
This commit is contained in:
Petr Skoda 2012-06-06 12:28:52 +02:00
parent 4db061680e
commit 5f9ba165de

View File

@ -63,10 +63,12 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
$text = "Moodle PHPUnit environment configuration warning:\n".$text;
break;
case PHPUNIT_EXITCODE_INSTALL:
$text = "Moodle PHPUnit environment is not initialised, please use:\n php admin/tool/phpunit/cli/init.php";
$path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
$text = "Moodle PHPUnit environment is not initialised, please use:\n php $path";
break;
case PHPUNIT_EXITCODE_REINSTALL:
$text = "Moodle PHPUnit environment was initialised for different version, please use:\n php admin/tool/phpunit/cli/init.php";
$path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
$text = "Moodle PHPUnit environment was initialised for different version, please use:\n php $path";
break;
default:
$text = empty($text) ? '' : ': '.$text;
@ -79,6 +81,32 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
exit($errorcode);
}
/**
* Returns relative path against current working directory,
* to be used for shell execution hints.
* @param string $moodlepath starting with "/", ex: "/admin/tool/cli/init.php"
* @return string path relative to current directory or absolute path
*/
function phpunit_bootstrap_cli_argument_path($moodlepath) {
global $CFG;
if (isset($CFG->admin) and $CFG->admin !== 'admin') {
$moodlepath = preg_replace('|^/admin/|', "/$CFG->admin/", $moodlepath);
}
$cwd = getcwd();
if (substr($cwd, -1) !== DIRECTORY_SEPARATOR) {
$cwd .= DIRECTORY_SEPARATOR;
}
$path = realpath($CFG->dirroot.$moodlepath);
if (strpos($path, $cwd) === 0) {
return substr($path, strlen($cwd));
}
return $path;
}
/**
* Mark empty dataroot to be used for testing.
* @param string $dataroot The dataroot directory