Example #1
0
/**
 * Print error and stop execution
 * @param int $errorcode The exit error code
 * @param string $text An error message to display
 * @return void stops code execution with error code
 */
function phpunit_bootstrap_error($errorcode, $text = '')
{
    switch ($errorcode) {
        case 0:
            // this is not an error, just print information and exit
            break;
        case 1:
            $text = 'Error: ' . $text;
            break;
        case PHPUNIT_EXITCODE_PHPUNITMISSING:
            $text = "Moodle can not find PHPUnit PEAR library";
            break;
        case PHPUNIT_EXITCODE_PHPUNITWRONG:
            $text = 'Moodle requires PHPUnit 3.6.x, ' . $text . ' is not compatible';
            break;
        case PHPUNIT_EXITCODE_PHPUNITEXTMISSING:
            $text = 'Moodle can not find required PHPUnit extension ' . $text;
            break;
        case PHPUNIT_EXITCODE_CONFIGERROR:
            $text = "Moodle PHPUnit environment configuration error:\n" . $text;
            break;
        case PHPUNIT_EXITCODE_CONFIGWARNING:
            $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');
            $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');
            $text = "Moodle PHPUnit environment was initialised for different version, please use:\n php {$path}";
            break;
        default:
            $text = empty($text) ? '' : ': ' . $text;
            $text = 'Unknown 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);
}
Example #2
0
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/upgradelib.php';
require_once $CFG->libdir . '/clilib.php';
require_once $CFG->libdir . '/pluginlib.php';
require_once $CFG->libdir . '/installlib.php';
if ($unrecognized) {
    $unrecognized = implode("\n  ", $unrecognized);
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
$diag = $options['diag'];
$drop = $options['drop'];
$install = $options['install'];
$buildconfig = $options['buildconfig'];
$buildcomponentconfigs = $options['buildcomponentconfigs'];
if ($options['help'] or !$drop and !$install and !$buildconfig and !$buildcomponentconfigs and !$diag) {
    $help = "Various PHPUnit utility functions\n\nOptions:\n--drop         Drop database and dataroot\n--install      Install database\n--diag         Diagnose installation and return error code only\n--run          Execute PHPUnit tests (alternative for standard phpunit binary)\n--buildconfig  Build /phpunit.xml from /phpunit.xml.dist that runs all tests\n--buildcomponentconfigs\n               Build distributed phpunit.xml files for each component\n\n-h, --help     Print out this help\n\nExample:\n\$ php " . phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/util.php') . " --install\n";
    echo $help;
    exit(0);
}
if ($diag) {
    list($errorcode, $message) = phpunit_util::testing_ready_problem();
    if ($errorcode) {
        phpunit_bootstrap_error($errorcode, $message);
    }
    exit(0);
} else {
    if ($buildconfig) {
        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');
Example #3
0
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
--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

Example:
\$ php ".phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/util.php')." --install
";
    echo $help;
    exit(0);
}

if ($diag) {
    list($errorcode, $message) = phpunit_util::testing_ready_problem();
    if ($errorcode) {
        phpunit_bootstrap_error($errorcode, $message);
    }
    exit(0);

} else if ($buildconfig) {
    if (phpunit_util::build_config_file()) {
        exit(0);