$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;
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