MediaWiki  REL1_22
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         'debug-tests' => false,
00016     );
00017 
00018     public function __construct() {
00019         foreach ( self::$additionalOptions as $option => $default ) {
00020             $this->longOptions[$option] = $option . 'Handler';
00021         }
00022     }
00023 
00024     protected function handleArguments( array $argv ) {
00025         parent::handleArguments( $argv );
00026 
00027         if ( !isset( $this->arguments['listeners'] ) ) {
00028             $this->arguments['listeners'] = array();
00029         }
00030 
00031         foreach ( $this->options[0] as $option ) {
00032             switch ( $option[0] ) {
00033                 case '--debug-tests':
00034                     $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener( 'PHPUnitCommand' );
00035                     break;
00036             }
00037         }
00038     }
00039 
00040     public static function main( $exit = true ) {
00041         $command = new self;
00042 
00043         if ( wfIsWindows() ) {
00044             # Windows does not come anymore with ANSI.SYS loaded by default
00045             # PHPUnit uses the suite.xml parameters to enable/disable colors
00046             # which can be then forced to be enabled with --colors.
00047             # The below code inject a parameter just like if the user called
00048             # phpunit with a --no-color option (which does not exist). It
00049             # overrides the suite.xml setting.
00050             # Probably fix bug 29226
00051             $command->arguments['colors'] = false;
00052         }
00053 
00054         # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
00055         # be able to resolve relative files inclusion such as suites/*
00056         # PHPUnit uses stream_resolve_include_path() internally
00057         # See bug 32022
00058         set_include_path(
00059             __DIR__
00060                 . PATH_SEPARATOR
00061                 . get_include_path()
00062         );
00063 
00064         $command->run( $_SERVER['argv'], $exit );
00065     }
00066 
00067     public function __call( $func, $args ) {
00068 
00069         if ( substr( $func, -7 ) == 'Handler' ) {
00070             if ( is_null( $args[0] ) ) {
00071                 $args[0] = true;
00072             } //Booleans
00073             self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
00074         }
00075     }
00076 
00077     public function run( array $argv, $exit = true ) {
00078         wfProfileIn( __METHOD__ );
00079 
00080         $ret = parent::run( $argv, false );
00081 
00082         wfProfileOut( __METHOD__ );
00083 
00084         // Return to real wiki db, so profiling data is preserved
00085         MediaWikiTestCase::teardownTestDB();
00086 
00087         // Log profiling data, e.g. in the database or UDP
00088         wfLogProfilingData();
00089 
00090         if ( $exit ) {
00091             exit( $ret );
00092         } else {
00093             return $ret;
00094         }
00095     }
00096 
00097     public function showHelp() {
00098         parent::showHelp();
00099 
00100         print <<<EOT
00101 
00102 ParserTest-specific options:
00103 
00104   --regex="<regex>"        Only run parser tests that match the given regex
00105   --file="<filename>"      File describing parser tests
00106   --keep-uploads           Re-use the same upload directory for each test, don't delete it
00107 
00108 
00109 Database options:
00110   --use-normal-tables      Use normal DB tables.
00111   --reuse-db               Init DB only if tables are missing and keep after finish.
00112 
00113 
00114 Debugging options:
00115   --debug-tests            Log testing activity to the PHPUnitCommand log channel.
00116 
00117 EOT;
00118     }
00119 }