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