Merge "Update outdated references to maintenance/ in documentation comments."
[mediawiki.git] / tests / phpunit / phpunit.php
blobe4cb6b6a6702f34104716b9776d1ec8adec31818
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Bootstrapping for MediaWiki PHPUnit tests
6 * @file
7 */
9 /* Configuration */
11 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not
12 define( 'MW_PHPUNIT_TEST', true );
14 // Start up MediaWiki in command-line mode
15 require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
17 class PHPUnitMaintClass extends Maintenance {
19 function __construct() {
20 parent::__construct();
21 $this->addOption( 'with-phpunitdir',
22 'Directory to include PHPUnit from, for example when using a git fetchout from upstream. Path will be prepended to PHP `include_path`.',
23 false, # not required
24 true # need arg
28 public function finalSetup() {
29 parent::finalSetup();
31 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
32 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
33 global $wgLocaltimezone, $wgLocalisationCacheConf;
34 global $wgDevelopmentWarnings;
36 // Inject test autoloader
37 require_once __DIR__ . '/../TestsAutoLoader.php';
39 // wfWarn should cause tests to fail
40 $wgDevelopmentWarnings = true;
42 $wgMainCacheType = CACHE_NONE;
43 $wgMessageCacheType = CACHE_NONE;
44 $wgParserCacheType = CACHE_NONE;
45 $wgLanguageConverterCacheType = CACHE_NONE;
47 $wgUseDatabaseMessages = false; # Set for future resets
49 // Assume UTC for testing purposes
50 $wgLocaltimezone = 'UTC';
52 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null';
54 // Bug 44192 Do not attempt to send a real e-mail
55 Hooks::clear( 'AlternateUserMailer' );
56 Hooks::register(
57 'AlternateUserMailer',
58 function () {
59 return false;
64 public function execute() {
65 global $IP;
67 # Make sure we have --configuration or PHPUnit might complain
68 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
69 //Hack to eliminate the need to use the Makefile (which sucks ATM)
70 array_splice( $_SERVER['argv'], 1, 0,
71 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
74 # --with-phpunitdir let us override the default PHPUnit version
75 if ( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
76 # Sanity checks
77 if ( !is_dir( $phpunitDir ) ) {
78 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
80 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
81 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
84 # Now prepends provided PHPUnit directory
85 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
86 set_include_path( $phpunitDir
87 . PATH_SEPARATOR . get_include_path() );
89 # Cleanup $args array so the option and its value do not
90 # pollute PHPUnit
91 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
92 unset( $_SERVER['argv'][$key] ); // the option
93 unset( $_SERVER['argv'][$key + 1] ); // its value
94 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
98 public function getDbType() {
99 return Maintenance::DB_ADMIN;
103 $maintClass = 'PHPUnitMaintClass';
104 require RUN_MAINTENANCE_IF_MAIN;
106 if ( !class_exists( 'PHPUnit_Runner_Version') ) {
107 require_once 'PHPUnit/Runner/Version.php';
110 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
111 && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' )
113 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
116 if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
117 require_once 'PHPUnit/Autoload.php';
119 MediaWikiPHPUnitCommand::main();