MediaWiki  REL1_21
MediaWikiPHPUnitCommand.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
00004 
00005         public static $additionalOptions = array(
00006                 'regex=' => false,
00007                 'file=' => false,
00008                 'use-filebackend=' => false,
00009                 'use-bagostuff=' => false,
00010                 'use-jobqueue=' => false,
00011                 'keep-uploads' => false,
00012                 'use-normal-tables' => false,
00013                 'reuse-db' => false,
00014                 'wiki=' => false,
00015         );
00016 
00017         public function __construct() {
00018                 foreach ( self::$additionalOptions as $option => $default ) {
00019                         $this->longOptions[$option] = $option . 'Handler';
00020                 }
00021 
00022         }
00023 
00024         public static function main( $exit = true ) {
00025                 $command = new self;
00026 
00027                 if ( wfIsWindows() ) {
00028                         # Windows does not come anymore with ANSI.SYS loaded by default
00029                         # PHPUnit uses the suite.xml parameters to enable/disable colors
00030                         # which can be then forced to be enabled with --colors.
00031                         # The below code inject a parameter just like if the user called
00032                         # phpunit with a --no-color option (which does not exist). It
00033                         # overrides the suite.xml setting.
00034                         # Probably fix bug 29226
00035                         $command->arguments['colors'] = false;
00036                 }
00037 
00038                 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
00039                 # be able to resolve relative files inclusion such as suites/*
00040                 # PHPUnit uses stream_resolve_include_path() internally
00041                 # See bug 32022
00042                 set_include_path(
00043                         __DIR__
00044                                 . PATH_SEPARATOR
00045                                 . get_include_path()
00046                 );
00047 
00048                 $command->run( $_SERVER['argv'], $exit );
00049         }
00050 
00051         public function __call( $func, $args ) {
00052 
00053                 if ( substr( $func, -7 ) == 'Handler' ) {
00054                         if ( is_null( $args[0] ) ) {
00055                                 $args[0] = true;
00056                         } //Booleans
00057                         self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
00058                 }
00059         }
00060 
00061         public function run( array $argv, $exit = true ) {
00062                 wfProfileIn( __METHOD__ );
00063 
00064                 $ret = parent::run( $argv, false );
00065 
00066                 wfProfileOut( __METHOD__ );
00067 
00068                 // Return to real wiki db, so profiling data is preserved
00069                 MediaWikiTestCase::teardownTestDB();
00070 
00071                 // Log profiling data, e.g. in the database or UDP
00072                 wfLogProfilingData();
00073 
00074                 if ( $exit ) {
00075                         exit( $ret );
00076                 } else {
00077                         return $ret;
00078                 }
00079         }
00080 
00081         public function showHelp() {
00082                 parent::showHelp();
00083 
00084                 print <<<EOT
00085 
00086 ParserTest-specific options:
00087 
00088   --regex="<regex>"        Only run parser tests that match the given regex
00089   --file="<filename>"      Prints the version and exits.
00090   --keep-uploads           Re-use the same upload directory for each test, don't delete it
00091 
00092 
00093 Database options:
00094   --use-normal-tables      Use normal DB tables.
00095   --reuse-db               Init DB only if tables are missing and keep after finish.
00096 
00097 
00098 EOT;
00099         }
00100 
00101 }