From: Kosta Harlan Date: Wed, 10 Jul 2019 17:20:00 +0000 (-0400) Subject: PHPUnit bootstrap: less aggressive unsetting of globals X-Git-Tag: 1.34.0-rc.0~1085^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=6140d94f450994eda761608041a2b204b372ad74;p=lhc%2Fweb%2Fwiklou.git PHPUnit bootstrap: less aggressive unsetting of globals Previous approach caused breakage with "Notice: Undefined index: _SERVER" messages, see e.g. https://gerrit.wikimedia.org/r/c/mediawiki/core/+/521268#message-4502e6c209f53f6dc1c7cdf4f60e5045bbfb6ee4 Change-Id: Ief20e4e21fd99d219ebef865c603e336c2609ce2 Follows-Up: I16691fc8ac063705ba0c2bc63b96c4534ca8660b Bug: T87781 --- diff --git a/tests/phpunit/MediaWikiUnitTestCase.php b/tests/phpunit/MediaWikiUnitTestCase.php index 3f0fc7a55d..43a333cb88 100644 --- a/tests/phpunit/MediaWikiUnitTestCase.php +++ b/tests/phpunit/MediaWikiUnitTestCase.php @@ -44,8 +44,8 @@ abstract class MediaWikiUnitTestCase extends TestCase { $GLOBALS = []; // Add back the minimal set of globals needed for unit tests to run for core + // extensions/skins. - foreach ( [ 'wgAutoloadClasses', 'wgAutoloadLocalClasses', 'IP' ] as $requiredGlobal ) { - $GLOBALS[$requiredGlobal] = $this->unitGlobals[ $requiredGlobal ]; + foreach ( $this->unitGlobals['wgPhpUnitBootstrapGlobals'] ?? [] as $key => $value ) { + $GLOBALS[ $key ] = $this->unitGlobals[ $key ]; } } diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 10348d4397..a7f0c09736 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -56,6 +56,12 @@ $IP = realpath( __DIR__ . '/../../' ); // these variables must be defined before setup runs $GLOBALS['IP'] = $IP; +// Set bootstrap globals to reuse in MediaWikiUnitTestCase +$bootstrapGlobals = []; +foreach ( $GLOBALS as $key => $value ) { + $bootstrapGlobals[ $key ] = $value; +} +$GLOBALS['wgPhpUnitBootstrapGlobals'] = $bootstrapGlobals; // Faking for Setup.php $GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test'; $GLOBALS['wgCommandLineMode'] = true;