Permalink
Browse files

Merge branch 'MDL-37458_master' of git://github.com/dmonllao/moodle

  • Loading branch information...
2 parents 73ce4ac + 0ea3558 commit 77ea8340de0382b966ee5eeb4166286f65892417 @danpoltawski danpoltawski committed Jan 21, 2013
@@ -28,6 +28,7 @@
require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
+require_once(__DIR__.'/../../../../lib/testing/lib.php');
echo "Initialising Moodle PHPUnit test environment...\n";
@@ -30,6 +30,7 @@
require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
+require_once(__DIR__.'/../../../../lib/testing/lib.php');
// now get cli options
list($options, $unrecognized) = cli_get_params(
@@ -110,7 +111,7 @@
-h, --help Print out this help
Example:
-\$ php ".phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/util.php')." --install
+\$ php ".testing_cli_argument_path('/admin/tool/phpunit/cli/util.php')." --install
";
echo $help;
exit(0);
@@ -136,7 +137,7 @@
} else if ($drop) {
// make sure tests do not run in parallel
- phpunit_util::acquire_test_lock();
+ test_lock::acquire('phpunit');
phpunit_util::drop_site(true);
// note: we must stop here because $CFG is messed up and we can not reinstall, sorry
exit(0);
@@ -32,6 +32,7 @@
ini_set('log_errors', '1');
require_once(__DIR__.'/bootstraplib.php');
+require_once(__DIR__.'/../testing/lib.php');
if (isset($_SERVER['REMOTE_ADDR'])) {
phpunit_bootstrap_error(1, 'Unit tests can be executed only from command line!');
@@ -133,7 +134,7 @@
}
// now we are 100% sure this dir is used only for phpunit tests
- phpunit_bootstrap_initdataroot($CFG->phpunit_dataroot);
+ testing_initdataroot($CFG->phpunit_dataroot, 'phpunit');
}
// verify db prefix
@@ -17,14 +17,16 @@
/**
* PHPUnit bootstrap function
*
- * Note: these functions must be self contained and must not rely on any library or include
+ * Note: these functions must be self contained and must not rely on any other library or include
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+require_once(__DIR__ . '/../testing/lib.php');
+
define('PHPUNIT_EXITCODE_PHPUNITMISSING', 129);
define('PHPUNIT_EXITCODE_PHPUNITWRONG', 130);
define('PHPUNIT_EXITCODE_PHPUNITEXTMISSING', 131);
@@ -63,11 +65,11 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
$text = "Moodle PHPUnit environment configuration warning:\n".$text;
break;
case PHPUNIT_EXITCODE_INSTALL:
- $path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
+ $path = testing_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:
- $path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
+ $path = testing_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:
@@ -76,90 +78,5 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
break;
}
- // do not write to error stream because we need the error message in PHP exec result from web ui
- echo($text."\n");
- 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) {
- $path = substr($path, strlen($cwd));
- }
-
- if (phpunit_bootstrap_is_cygwin()) {
- $path = str_replace('\\', '/', $path);
- }
-
- return $path;
-}
-
-/**
- * Mark empty dataroot to be used for testing.
- * @param string $dataroot The dataroot directory
- * @return void
- */
-function phpunit_bootstrap_initdataroot($dataroot) {
- global $CFG;
- umask(0);
- if (!file_exists("$dataroot/phpunittestdir.txt")) {
- file_put_contents("$dataroot/phpunittestdir.txt", 'Contents of this directory are used during tests only, do not delete this file!');
- }
- phpunit_boostrap_fix_file_permissions("$dataroot/phpunittestdir.txt");
- if (!file_exists("$CFG->phpunit_dataroot/phpunit")) {
- mkdir("$CFG->phpunit_dataroot/phpunit", $CFG->directorypermissions);
- }
-}
-
-/**
- * Try to change permissions to $CFG->dirroot or $CFG->dataroot if possible
- * @param string $file
- * @return bool success
- */
-function phpunit_boostrap_fix_file_permissions($file) {
- global $CFG;
-
- $permissions = fileperms($file);
- if ($permissions & $CFG->filepermissions != $CFG->filepermissions) {
- $permissions = $permissions | $CFG->filepermissions;
- return chmod($file, $permissions);
- }
-
- return true;
-}
-
-/**
- * Find out if running under Cygwin on Windows.
- * @return bool
- */
-function phpunit_bootstrap_is_cygwin() {
- if (empty($_SERVER['OS']) or $_SERVER['OS'] !== 'Windows_NT') {
- return false;
-
- } else if (!empty($_SERVER['SHELL']) and $_SERVER['SHELL'] === '/bin/bash') {
- return true;
-
- } else if (!empty($_SERVER['TERM']) and $_SERVER['TERM'] === 'cygwin') {
- return true;
-
- } else {
- return false;
- }
+ testing_error($errorcode, $text);
}
@@ -106,7 +106,7 @@ protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) {
if (!$executable) {
$executable = 'phpunit';
- if (phpunit_bootstrap_is_cygwin()) {
+ if (testing_is_cygwin()) {
$file = str_replace('\\', '/', $file);
$executable = 'phpunit.bat';
}
Oops, something went wrong.

0 comments on commit 77ea834

Please sign in to comment.