on-demand release 4.0dev+
[moodle.git] / lib / phpunit / bootstraplib.php
CommitLineData
7b0ff213
PS
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * PHPUnit bootstrap function
19 *
0ea35584 20 * Note: these functions must be self contained and must not rely on any other library or include
7b0ff213
PS
21 *
22 * @package core
23 * @category phpunit
24 * @copyright 2012 Petr Skoda {@link http://skodak.org}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
0ea35584
DM
28require_once(__DIR__ . '/../testing/lib.php');
29
0d8e51a6
PS
30define('PHPUNIT_EXITCODE_PHPUNITMISSING', 129);
31define('PHPUNIT_EXITCODE_PHPUNITWRONG', 130);
32define('PHPUNIT_EXITCODE_PHPUNITEXTMISSING', 131);
33define('PHPUNIT_EXITCODE_CONFIGERROR', 135);
34define('PHPUNIT_EXITCODE_CONFIGWARNING', 136);
35define('PHPUNIT_EXITCODE_INSTALL', 140);
36define('PHPUNIT_EXITCODE_REINSTALL', 141);
37
7b0ff213
PS
38/**
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
43 */
44function phpunit_bootstrap_error($errorcode, $text = '') {
45 switch ($errorcode) {
219d1a4e
PS
46 case 0:
47 // this is not an error, just print information and exit
48 break;
7b0ff213
PS
49 case 1:
50 $text = 'Error: '.$text;
51 break;
0d8e51a6 52 case PHPUNIT_EXITCODE_PHPUNITMISSING:
d7861370 53 $text = "Can not find PHPUnit library, to install use: php composer.phar install";
0d8e51a6
PS
54 break;
55 case PHPUNIT_EXITCODE_PHPUNITWRONG:
b5b10866
PS
56 $text = 'Moodle requires PHPUnit 3.6.x, '.$text.' is not compatible';
57 break;
0d8e51a6
PS
58 case PHPUNIT_EXITCODE_PHPUNITEXTMISSING:
59 $text = 'Moodle can not find required PHPUnit extension '.$text;
b5b10866 60 break;
0d8e51a6
PS
61 case PHPUNIT_EXITCODE_CONFIGERROR:
62 $text = "Moodle PHPUnit environment configuration error:\n".$text;
7b0ff213 63 break;
0d8e51a6
PS
64 case PHPUNIT_EXITCODE_CONFIGWARNING:
65 $text = "Moodle PHPUnit environment configuration warning:\n".$text;
7b0ff213 66 break;
0d8e51a6 67 case PHPUNIT_EXITCODE_INSTALL:
0ea35584 68 $path = testing_cli_argument_path('/admin/tool/phpunit/cli/init.php');
5f9ba165 69 $text = "Moodle PHPUnit environment is not initialised, please use:\n php $path";
7b0ff213 70 break;
0d8e51a6 71 case PHPUNIT_EXITCODE_REINSTALL:
0ea35584 72 $path = testing_cli_argument_path('/admin/tool/phpunit/cli/init.php');
5f9ba165 73 $text = "Moodle PHPUnit environment was initialised for different version, please use:\n php $path";
7b0ff213
PS
74 break;
75 default:
76 $text = empty($text) ? '' : ': '.$text;
77 $text = 'Unknown error '.$errorcode.$text;
78 break;
79 }
0d8e51a6 80
0ea35584 81 testing_error($errorcode, $text);
d606bee9 82}