MediaWiki  master
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( __DIR__ ) );
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;
00035                 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
00036                 global $wgLocaltimezone, $wgLocalisationCacheConf;
00037                 global $wgDevelopmentWarnings;
00038 
00039                 // wfWarn should cause tests to fail
00040                 $wgDevelopmentWarnings = true;
00041 
00042                 $wgMainCacheType = CACHE_NONE;
00043                 $wgMessageCacheType = CACHE_NONE;
00044                 $wgParserCacheType = CACHE_NONE;
00045                 $wgLanguageConverterCacheType = CACHE_NONE;
00046 
00047                 $wgUseDatabaseMessages = false; # Set for future resets
00048 
00049                 // Assume UTC for testing purposes
00050                 $wgLocaltimezone = 'UTC';
00051 
00052                 $wgLocalisationCacheConf['storeClass'] =  'LCStore_Null';
00053         }
00054 
00055         public function execute() {
00056                 global $IP;
00057 
00058                 # Make sure we have --configuration or PHPUnit might complain
00059                 if( !in_array( '--configuration', $_SERVER['argv'] ) ) {
00060                         //Hack to eliminate the need to use the Makefile (which sucks ATM)
00061                         array_splice( $_SERVER['argv'], 1, 0,
00062                                 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
00063                 }
00064 
00065                 # --with-phpunitdir let us override the default PHPUnit version
00066                 if( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
00067                         # Sanity checks
00068                         if( !is_dir($phpunitDir) ) {
00069                                 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
00070                         }
00071                         if( !is_readable( $phpunitDir."/PHPUnit/Runner/Version.php" ) ) {
00072                                 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
00073                         }
00074 
00075                         # Now prepends provided PHPUnit directory
00076                         $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
00077                         set_include_path( $phpunitDir
00078                                 . PATH_SEPARATOR . get_include_path() );
00079 
00080                         # Cleanup $args array so the option and its value do not
00081                         # pollute PHPUnit
00082                         $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
00083                         unset( $_SERVER['argv'][$key]   ); // the option
00084                         unset( $_SERVER['argv'][$key+1] ); // its value
00085                         $_SERVER['argv'] = array_values( $_SERVER['argv'] );
00086 
00087                 }
00088         }
00089 
00090         public function getDbType() {
00091                 return Maintenance::DB_ADMIN;
00092         }
00093 }
00094 
00095 $maintClass = 'PHPUnitMaintClass';
00096 require( RUN_MAINTENANCE_IF_MAIN );
00097 
00098 require_once( 'PHPUnit/Runner/Version.php' );
00099 
00100 if( PHPUnit_Runner_Version::id() !== '@package_version@'
00101    && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' ) ) {
00102         die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
00103 }
00104 require_once( 'PHPUnit/Autoload.php' );
00105 
00106 require_once( "$IP/tests/TestsAutoLoader.php" );
00107 MediaWikiPHPUnitCommand::main();