X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCase.php;h=486b16de85c5edb12e918f9f2f06082f45a0d950;hb=742c4988b9c10af39909dceaec3997dcc8745b48;hp=329f0ba12df6719a131da75387cbd269e62ead36;hpb=81c91fd493fd52926b454826d621c60b7818503f;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 329f0ba12d..486b16de85 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -817,29 +817,6 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { return false; } - /** - * Stashes the global, will be restored in tearDown() - * - * Individual test functions may override globals through the setMwGlobals() function - * or directly. When directly overriding globals their keys should first be passed to this - * method in setUp to avoid breaking global state for other tests - * - * That way all other tests are executed with the same settings (instead of using the - * unreliable local settings for most tests and fix it only for some tests). - * - * @param array|string $globalKeys Key to the global variable, or an array of keys. - * - * @note To allow changes to global variables to take effect on global service instances, - * call overrideMwServices(). - * - * @since 1.23 - * @deprecated since 1.32, use setMwGlobals() and don't alter globals directly - */ - protected function stashMwGlobals( $globalKeys ) { - wfDeprecated( __METHOD__, '1.32' ); - $this->doStashMwGlobals( $globalKeys ); - } - private function doStashMwGlobals( $globalKeys ) { if ( is_string( $globalKeys ) ) { $globalKeys = [ $globalKeys ]; @@ -977,6 +954,8 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { $newInstance->redefineService( $name, $callback ); } + self::resetGlobalParser(); + return $newInstance; } @@ -1041,6 +1020,9 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { ); MediaWikiServices::forceGlobalInstance( $newServices ); + + self::resetGlobalParser(); + return $newServices; } @@ -1069,9 +1051,26 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( self::$originalServices ); $currentServices->destroy(); + self::resetGlobalParser(); + 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. + */ + private static function resetGlobalParser() { + // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser + global $wgParser; + if ( $wgParser instanceof StubObject ) { + return; + } + $wgParser = new StubObject( 'wgParser', function () { + return MediaWikiServices::getInstance()->getParser(); + } ); + } + /** * @since 1.27 * @param string|Language $lang