MediaWiki
REL1_21
|
00001 #!/usr/bin/env php 00002 <?php 00009 /* Configuration */ 00010 00011 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not 00012 define( 'MW_PHPUNIT_TEST', true ); 00013 00014 // Start up MediaWiki in command-line mode 00015 require_once( dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php" ); 00016 00017 class PHPUnitMaintClass extends Maintenance { 00018 00019 function __construct() { 00020 parent::__construct(); 00021 $this->addOption( 'with-phpunitdir', 00022 'Directory to include PHPUnit from, for example when using a git fetchout from upstream. Path will be prepended to PHP `include_path`.', 00023 false, # not required 00024 true # need arg 00025 ); 00026 } 00027 00028 public function finalSetup() { 00029 parent::finalSetup(); 00030 00031 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; 00032 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; 00033 global $wgLocaltimezone, $wgLocalisationCacheConf; 00034 global $wgDevelopmentWarnings; 00035 00036 // wfWarn should cause tests to fail 00037 $wgDevelopmentWarnings = true; 00038 00039 $wgMainCacheType = CACHE_NONE; 00040 $wgMessageCacheType = CACHE_NONE; 00041 $wgParserCacheType = CACHE_NONE; 00042 $wgLanguageConverterCacheType = CACHE_NONE; 00043 00044 $wgUseDatabaseMessages = false; # Set for future resets 00045 00046 // Assume UTC for testing purposes 00047 $wgLocaltimezone = 'UTC'; 00048 00049 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null'; 00050 00051 // Bug 44192 Do not attempt to send a real e-mail 00052 Hooks::clear( 'AlternateUserMailer' ); 00053 Hooks::register( 'AlternateUserMailer', 00054 function() { return false; } 00055 ); 00056 } 00057 00058 public function execute() { 00059 global $IP; 00060 00061 # Make sure we have --configuration or PHPUnit might complain 00062 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) { 00063 //Hack to eliminate the need to use the Makefile (which sucks ATM) 00064 array_splice( $_SERVER['argv'], 1, 0, 00065 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) ); 00066 } 00067 00068 # --with-phpunitdir let us override the default PHPUnit version 00069 if ( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) { 00070 # Sanity checks 00071 if ( !is_dir( $phpunitDir ) ) { 00072 $this->error( "--with-phpunitdir should be set to an existing directory", 1 ); 00073 } 00074 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) { 00075 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 ); 00076 } 00077 00078 # Now prepends provided PHPUnit directory 00079 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" ); 00080 set_include_path( $phpunitDir 00081 . PATH_SEPARATOR . get_include_path() ); 00082 00083 # Cleanup $args array so the option and its value do not 00084 # pollute PHPUnit 00085 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] ); 00086 unset( $_SERVER['argv'][$key] ); // the option 00087 unset( $_SERVER['argv'][$key + 1] ); // its value 00088 $_SERVER['argv'] = array_values( $_SERVER['argv'] ); 00089 00090 } 00091 } 00092 00093 public function getDbType() { 00094 return Maintenance::DB_ADMIN; 00095 } 00096 } 00097 00098 $maintClass = 'PHPUnitMaintClass'; 00099 require( RUN_MAINTENANCE_IF_MAIN ); 00100 00101 require_once( 'PHPUnit/Runner/Version.php' ); 00102 00103 if ( PHPUnit_Runner_Version::id() !== '@package_version@' 00104 && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' ) 00105 ) { 00106 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" ); 00107 } 00108 require_once( 'PHPUnit/Autoload.php' ); 00109 00110 require_once( "$IP/tests/TestsAutoLoader.php" ); 00111 MediaWikiPHPUnitCommand::main();