Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   *
  20   * Note: these functions must be self contained and must not rely on any other library or include
  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  
  28  require_once (__DIR__ . '/../testing/lib.php');
  29  
  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);
  37  
  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   */
  44  function phpunit_bootstrap_error($errorcode, $text = '') {
  45      switch ($errorcode) {
  46          case 0:
  47              // this is not an error, just print information and exit
  48              break;
  49          case 1:
  50              $text = 'Error: '.$text;
  51              break;
  52          case PHPUNIT_EXITCODE_PHPUNITMISSING:
  53              $text = "Can not find PHPUnit library, to install use: php composer.phar install";
  54              break;
  55          case PHPUNIT_EXITCODE_PHPUNITWRONG:
  56              $text = 'Moodle requires PHPUnit 3.6.x, '.$text.' is not compatible';
  57              break;
  58          case PHPUNIT_EXITCODE_PHPUNITEXTMISSING:
  59              $text = 'Moodle can not find required PHPUnit extension '.$text;
  60              break;
  61          case PHPUNIT_EXITCODE_CONFIGERROR:
  62              $text = "Moodle PHPUnit environment configuration error:\n".$text;
  63              break;
  64          case PHPUNIT_EXITCODE_CONFIGWARNING:
  65              $text = "Moodle PHPUnit environment configuration warning:\n".$text;
  66              break;
  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";
  70              break;
  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";
  74              break;
  75          default:
  76              $text = empty($text) ? '' : ': '.$text;
  77              $text = 'Unknown error '.$errorcode.$text;
  78              break;
  79      }
  80  
  81      testing_error($errorcode, $text);
  82  }