Merge "Remove unused argument"
[lhc/web/wiklou.git] / tests / phpunit / phpunit.php
index 63313cf..587d6d0 100755 (executable)
@@ -55,7 +55,7 @@ class PHPUnitMaintClass extends Maintenance {
        public function finalSetup() {
                parent::finalSetup();
 
-               global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
+               global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
                global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
                global $wgLocaltimezone, $wgLocalisationCacheConf;
                global $wgDevelopmentWarnings;
@@ -67,6 +67,7 @@ class PHPUnitMaintClass extends Maintenance {
                $wgDevelopmentWarnings = true;
 
                $wgMainCacheType = CACHE_NONE;
+               $wgMainWANCache = CACHE_NONE;
                $wgMessageCacheType = CACHE_NONE;
                $wgParserCacheType = CACHE_NONE;
                $wgLanguageConverterCacheType = CACHE_NONE;
@@ -93,6 +94,12 @@ class PHPUnitMaintClass extends Maintenance {
        public function execute() {
                global $IP;
 
+               // Deregister handler from MWExceptionHandler::installHandle so that PHPUnit's own handler
+               // stays in tact.
+               // Has to in execute() instead of finalSetup(), because finalSetup() runs before
+               // doMaintenance.php includes Setup.php, which calls MWExceptionHandler::installHandle().
+               restore_error_handler();
+
                $this->forceFormatServerArgv();
 
                # Make sure we have --configuration or PHPUnit might complain
@@ -148,17 +155,17 @@ class PHPUnitMaintClass extends Maintenance {
                }
 
                $key = array_search( '--debug-tests', $_SERVER['argv'] );
-               if( $key !== false && array_search( '--printer', $_SERVER['argv'] ) === false ) {
+               if ( $key !== false && array_search( '--printer', $_SERVER['argv'] ) === false ) {
                        unset( $_SERVER['argv'][$key] );
                        array_splice( $_SERVER['argv'], 1, 0, 'MediaWikiPHPUnitTestListener' );
                        array_splice( $_SERVER['argv'], 1, 0, '--printer' );
                }
 
-               foreach( self::$additionalOptions as $option => $default ) {
+               foreach ( self::$additionalOptions as $option => $default ) {
                        $key = array_search( '--' . $option, $_SERVER['argv'] );
-                       if( $key !== false ) {
+                       if ( $key !== false ) {
                                unset( $_SERVER['argv'][$key] );
-                               if( $this->mParams[$option]['withArg'] ) {
+                               if ( $this->mParams[$option]['withArg'] ) {
                                        self::$additionalOptions[$option] = $_SERVER['argv'][$key + 1];
                                        unset( $_SERVER['argv'][$key + 1] );
                                } else {
@@ -179,11 +186,11 @@ class PHPUnitMaintClass extends Maintenance {
         */
        private function forceFormatServerArgv() {
                $argv = array();
-               foreach( $_SERVER['argv'] as $key => $arg ) {
-                       if( $key === 0 ) {
+               foreach ( $_SERVER['argv'] as $key => $arg ) {
+                       if ( $key === 0 ) {
                                $argv[0] = $arg;
                        } elseif ( strstr( $arg, '=' ) ) {
-                               foreach( explode( '=', $arg, 2 ) as $argPart ) {
+                               foreach ( explode( '=', $arg, 2 ) as $argPart ) {
                                        $argv[] = $argPart;
                                }
                        } else {
@@ -209,25 +216,35 @@ if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
 
 $ok = false;
 
-foreach( array(
-       stream_resolve_include_path( 'phpunit.phar' ),
-       'PHPUnit/Runner/Version.php',
-       'PHPUnit/Autoload.php'
-) as $includePath ) {
-       @include_once( $includePath );
-       if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
-               $ok = true;
-               break;
+if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
+       echo "PHPUnit already present\n";
+       $ok = true;
+} else {
+       foreach ( array(
+                               stream_resolve_include_path( 'phpunit.phar' ),
+                               'PHPUnit/Runner/Version.php',
+                               'PHPUnit/Autoload.php'
+                       ) as $includePath ) {
+               // @codingStandardsIgnoreStart
+               @include_once $includePath;
+               // @codingStandardsIgnoreEnd
+               if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
+                       $ok = true;
+                       echo "Using PHPUnit from $includePath\n";
+                       break;
+               }
        }
 }
 
 if ( !$ok ) {
-       die( "Couldn't find a usable PHPUnit.\n" );
+       echo "Couldn't find a usable PHPUnit.\n";
+       exit( 1 );
 }
 
 $puVersion = PHPUnit_Runner_Version::id();
 if ( $puVersion !== '@package_version@' && version_compare( $puVersion, '3.7.0', '<' ) ) {
-       die( "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n" );
+       echo "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n";
+       exit( 1 );
 }
 
 PHPUnit_TextUI_Command::main();