4 * Bootstrapping for MediaWiki PHPUnit tests
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`.',
28 public function finalSetup() {
31 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
32 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
33 global $wgLocaltimezone, $wgLocalisationCacheConf;
34 global $wgDevelopmentWarnings;
36 // wfWarn should cause tests to fail
37 $wgDevelopmentWarnings = true;
39 $wgMainCacheType = CACHE_NONE
;
40 $wgMessageCacheType = CACHE_NONE
;
41 $wgParserCacheType = CACHE_NONE
;
42 $wgLanguageConverterCacheType = CACHE_NONE
;
44 $wgUseDatabaseMessages = false; # Set for future resets
46 // Assume UTC for testing purposes
47 $wgLocaltimezone = 'UTC';
49 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null';
52 public function execute() {
55 # Make sure we have --configuration or PHPUnit might complain
56 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
57 //Hack to eliminate the need to use the Makefile (which sucks ATM)
58 array_splice( $_SERVER['argv'], 1, 0,
59 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
62 # --with-phpunitdir let us override the default PHPUnit version
63 if ( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
65 if ( !is_dir( $phpunitDir ) ) {
66 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
68 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
69 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
72 # Now prepends provided PHPUnit directory
73 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
74 set_include_path( $phpunitDir
75 . PATH_SEPARATOR
. get_include_path() );
77 # Cleanup $args array so the option and its value do not
79 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
80 unset( $_SERVER['argv'][$key] ); // the option
81 unset( $_SERVER['argv'][$key +
1] ); // its value
82 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
87 public function getDbType() {
88 return Maintenance
::DB_ADMIN
;
92 $maintClass = 'PHPUnitMaintClass';
93 require( RUN_MAINTENANCE_IF_MAIN
);
95 require_once( 'PHPUnit/Runner/Version.php' );
97 if ( PHPUnit_Runner_Version
::id() !== '@package_version@'
98 && version_compare( PHPUnit_Runner_Version
::id(), '3.6.7', '<' )
100 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version
::id() . ".\n" );
102 require_once( 'PHPUnit/Autoload.php' );
104 require_once( "$IP/tests/TestsAutoLoader.php" );
105 MediaWikiPHPUnitCommand
::main();