Merge "Split revdelete-text on Special:RevisionDelete for each type"
[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 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not
10 define( 'MW_PHPUNIT_TEST', true );
11
12 // Start up MediaWiki in command-line mode
13 require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
14
15 class PHPUnitMaintClass extends Maintenance {
16
17 public function __construct() {
18 parent::__construct();
19 $this->addOption( 'with-phpunitdir',
20 'Directory to include PHPUnit from, for example when using a git fetchout from upstream. Path will be prepended to PHP `include_path`.',
21 false, # not required
22 true # need arg
23 );
24 }
25
26 public function finalSetup() {
27 parent::finalSetup();
28
29 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
30 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
31 global $wgLocaltimezone, $wgLocalisationCacheConf;
32 global $wgDevelopmentWarnings;
33
34 // Inject test autoloader
35 require_once __DIR__ . '/../TestsAutoLoader.php';
36
37 // wfWarn should cause tests to fail
38 $wgDevelopmentWarnings = true;
39
40 $wgMainCacheType = CACHE_NONE;
41 $wgMessageCacheType = CACHE_NONE;
42 $wgParserCacheType = CACHE_NONE;
43 $wgLanguageConverterCacheType = CACHE_NONE;
44
45 $wgUseDatabaseMessages = false; # Set for future resets
46
47 // Assume UTC for testing purposes
48 $wgLocaltimezone = 'UTC';
49
50 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
51
52 // Bug 44192 Do not attempt to send a real e-mail
53 Hooks::clear( 'AlternateUserMailer' );
54 Hooks::register(
55 'AlternateUserMailer',
56 function () {
57 return false;
58 }
59 );
60 }
61
62 public function execute() {
63 global $IP;
64
65 # Make sure we have --configuration or PHPUnit might complain
66 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
67 //Hack to eliminate the need to use the Makefile (which sucks ATM)
68 array_splice( $_SERVER['argv'], 1, 0,
69 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
70 }
71
72 # --with-phpunitdir let us override the default PHPUnit version
73 if ( $this->hasOption( 'with-phpunitdir' ) ) {
74 $phpunitDir = $this->getOption( 'with-phpunitdir' );
75 # Sanity checks
76 if ( !is_dir( $phpunitDir ) ) {
77 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
78 }
79 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
80 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
81 }
82
83 # Now prepends provided PHPUnit directory
84 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
85 set_include_path( $phpunitDir . PATH_SEPARATOR . get_include_path() );
86
87 # Cleanup $args array so the option and its value do not
88 # pollute PHPUnit
89 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
90 unset( $_SERVER['argv'][$key] ); // the option
91 unset( $_SERVER['argv'][$key + 1] ); // its value
92 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
93 }
94 }
95
96 public function getDbType() {
97 return Maintenance::DB_ADMIN;
98 }
99 }
100
101 $maintClass = 'PHPUnitMaintClass';
102 require RUN_MAINTENANCE_IF_MAIN;
103
104 if ( !class_exists( 'PHPUnit_Runner_Version' ) ) {
105 require_once 'PHPUnit/Runner/Version.php';
106 }
107
108 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
109 && version_compare( PHPUnit_Runner_Version::id(), '3.7.0', '<' )
110 ) {
111 die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
112 }
113
114 if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
115 require_once 'PHPUnit/Autoload.php';
116 }
117 MediaWikiPHPUnitCommand::main();