Merge "phpunit: Add more info to LocalSettings.php error in MediaWikiIntegrationTestCase"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 2 Sep 2019 08:55:51 +0000 (08:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 2 Sep 2019 08:55:51 +0000 (08:55 +0000)
1  2 
tests/phpunit/MediaWikiIntegrationTestCase.php

@@@ -182,8 -182,10 +182,10 @@@ abstract class MediaWikiIntegrationTest
                global $IP;
                parent::setUpBeforeClass();
                if ( !file_exists( "$IP/LocalSettings.php" ) ) {
-                       echo 'A working MediaWiki installation with a configured LocalSettings.php file is'
-                       . ' required for tests that extend ' . self::class;
+                               echo "File \"$IP/LocalSettings.php\" could not be found. "
+                               . "Test case " . static::class . " extends " . self::class . " "
+                               . "which requires a working MediaWiki installation.\n"
+                               . ( new RuntimeException() )->getTraceAsString();
                        die();
                }
                self::initializeForStandardPhpunitEntrypointIfNeeded();
                        $instantiator
                );
  
 -              if ( $name === 'ContentLanguage' ) {
 -                      $this->setMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] );
 -              }
 +              self::resetLegacyGlobals();
        }
  
        /**
                        $this->localServices->resetServiceForTesting( $name, true );
                }
  
 -              self::resetGlobalParser();
 +              self::resetLegacyGlobals();
                Language::clearCaches();
        }
  
                        $newInstance->redefineService( $name, $callback );
                }
  
 -              self::resetGlobalParser();
 +              self::resetLegacyGlobals();
  
                return $newInstance;
        }
  
                MediaWikiServices::forceGlobalInstance( $newServices );
  
 -              self::resetGlobalParser();
 +              self::resetLegacyGlobals();
  
                return $newServices;
        }
                MediaWikiServices::forceGlobalInstance( self::$originalServices );
                $currentServices->destroy();
  
 -              self::resetGlobalParser();
 +              self::resetLegacyGlobals();
  
                return true;
        }
  
        /**
 -       * If $wgParser has been unstubbed, replace it with a fresh one so it picks up any config
 -       * changes. $wgParser is deprecated, but we still support it for now.
 +       * If legacy globals such as $wgParser or $wgContLang have been unstubbed, replace them with
 +       * fresh ones so they pick up any config changes. They're deprecated, but we still support them
 +       * for now.
         */
 -      private static function resetGlobalParser() {
 +      private static function resetLegacyGlobals() {
                // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser
 -              global $wgParser;
 -              if ( $wgParser instanceof StubObject ) {
 -                      return;
 +              global $wgParser, $wgContLang;
 +              if ( !( $wgParser instanceof StubObject ) ) {
 +                      $wgParser = new StubObject( 'wgParser', function () {
 +                              return MediaWikiServices::getInstance()->getParser();
 +                      } );
 +              }
 +              if ( !( $wgContLang instanceof StubObject ) ) {
 +                      $wgContlang = new StubObject( 'wgContLang', function () {
 +                              return MediaWikiServices::getInstance()->getContLang();
 +                      } );
                }
 -              $wgParser = new StubObject( 'wgParser', function () {
 -                      return MediaWikiServices::getInstance()->getParser();
 -              } );
        }
  
        /**
        }
  
        /**
 +       * @deprecated since 1.34, use setMwGlobals( 'wgLanguageCode' ) to set the code or
 +       *   setService( 'ContentLanguage' ) to set an object
         * @since 1.27
         * @param string|Language $lang
         */
                        $this->setService( 'ContentLanguage', $lang );
                        $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() );
                } else {
 -                      $this->setMwGlobals( [
 -                              'wgLanguageCode' => $lang,
 -                              'wgContLang' => Language::factory( $lang ),
 -                      ] );
 +                      $this->setMwGlobals( 'wgLanguageCode', $lang );
                }
        }