2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * PHPUnit bootstrap function
20 * Note: these functions must be self contained and must not rely on any other library or include
24 * @copyright 2012 Petr Skoda {@link http://skodak.org}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once(__DIR__
. '/../testing/lib.php');
30 define('PHPUNIT_EXITCODE_PHPUNITMISSING', 129);
31 define('PHPUNIT_EXITCODE_PHPUNITWRONG', 130);
32 define('PHPUNIT_EXITCODE_PHPUNITEXTMISSING', 131);
33 define('PHPUNIT_EXITCODE_CONFIGERROR', 135);
34 define('PHPUNIT_EXITCODE_CONFIGWARNING', 136);
35 define('PHPUNIT_EXITCODE_INSTALL', 140);
36 define('PHPUNIT_EXITCODE_REINSTALL', 141);
39 * Print error and stop execution
40 * @param int $errorcode The exit error code
41 * @param string $text An error message to display
42 * @return void stops code execution with error code
44 function phpunit_bootstrap_error($errorcode, $text = '') {
47 // this is not an error, just print information and exit
50 $text = 'Error: '.$text;
52 case PHPUNIT_EXITCODE_PHPUNITMISSING
:
53 $text = "Can not find PHPUnit library, to install use: php composer.phar install";
55 case PHPUNIT_EXITCODE_PHPUNITWRONG
:
56 $text = 'Moodle requires PHPUnit 3.6.x, '.$text.' is not compatible';
58 case PHPUNIT_EXITCODE_PHPUNITEXTMISSING
:
59 $text = 'Moodle can not find required PHPUnit extension '.$text;
61 case PHPUNIT_EXITCODE_CONFIGERROR
:
62 $text = "Moodle PHPUnit environment configuration error:\n".$text;
64 case PHPUNIT_EXITCODE_CONFIGWARNING
:
65 $text = "Moodle PHPUnit environment configuration warning:\n".$text;
67 case PHPUNIT_EXITCODE_INSTALL
:
68 $path = testing_cli_argument_path('/admin/tool/phpunit/cli/init.php');
69 $text = "Moodle PHPUnit environment is not initialised, please use:\n php $path";
71 case PHPUNIT_EXITCODE_REINSTALL
:
72 $path = testing_cli_argument_path('/admin/tool/phpunit/cli/init.php');
73 $text = "Moodle PHPUnit environment was initialised for different version, please use:\n php $path";
76 $text = empty($text) ?
'' : ': '.$text;
77 $text = 'Unknown error '.$errorcode.$text;
81 testing_error($errorcode, $text);