Merge "(bug 17602) fix Monobook action tabs not quite touching the page body"
[lhc/web/wiklou.git] / tests / phpunit / phpunit.php
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Bootstrapping for MediaWiki PHPUnit tests
5 *
6 * @file
7 */
8
9 /* Configuration */
10
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 );
13
14 // Start up MediaWiki in command-line mode
15 require_once( dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php" );
16
17 class PHPUnitMaintClass extends Maintenance {
18
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
25 );
26 }
27
28 public function finalSetup() {
29 parent::finalSetup();
30
31 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
32 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
33 global $wgLocaltimezone, $wgLocalisationCacheConf;
34 global $wgDevelopmentWarnings;
35
36 // wfWarn should cause tests to fail
37 $wgDevelopmentWarnings = true;
38
39 $wgMainCacheType = CACHE_NONE;
40 $wgMessageCacheType = CACHE_NONE;
41 $wgParserCacheType = CACHE_NONE;
42 $wgLanguageConverterCacheType = CACHE_NONE;
43
44 $wgUseDatabaseMessages = false; # Set for future resets
45
46 // Assume UTC for testing purposes
47 $wgLocaltimezone = 'UTC';
48
49 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null';
50
51 // Bug 44192 Do not attempt to send a real e-mail
52 Hooks::clear( 'AlternateUserMailer' );
53 Hooks::register(
54 'AlternateUserMailer',
55 function () {
56 return false;
57 }
58 );
59 }
60
61 public function execute() {
62 global $IP;
63
64 # Make sure we have --configuration or PHPUnit might complain
65 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
66 //Hack to eliminate the need to use the Makefile (which sucks ATM)
67 array_splice( $_SERVER['argv'], 1, 0,
68 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
69 }
70
71 # --with-phpunitdir let us override the default PHPUnit version
72 if ( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
73 # Sanity checks
74 if ( !is_dir( $phpunitDir ) ) {
75 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
76 }
77 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
78 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
79 }
80
81 # Now prepends provided PHPUnit directory
82 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
83 set_include_path( $phpunitDir
84 . PATH_SEPARATOR . get_include_path() );
85
86 # Cleanup $args array so the option and its value do not
87 # pollute PHPUnit
88 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
89 unset( $_SERVER['argv'][$key] ); // the option
90 unset( $_SERVER['argv'][$key + 1] ); // its value
91 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
92 }
93 }
94
95 public function getDbType() {
96 return Maintenance::DB_ADMIN;
97 }
98 }
99
100 $maintClass = 'PHPUnitMaintClass';
101 require( RUN_MAINTENANCE_IF_MAIN );
102
103 require_once 'PHPUnit/Runner/Version.php';
104
105 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
106 && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' )
107 ) {
108 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
109 }
110 require_once 'PHPUnit/Autoload.php';
111
112 require_once( "$IP/tests/TestsAutoLoader.php" );
113 MediaWikiPHPUnitCommand::main();