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