PHPUnit bootstrap: less aggressive unsetting of globals
authorKosta Harlan <kharlan@wikimedia.org>
Wed, 10 Jul 2019 17:20:00 +0000 (13:20 -0400)
committerKosta Harlan <kharlan@wikimedia.org>
Wed, 10 Jul 2019 17:51:55 +0000 (13:51 -0400)
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

tests/phpunit/MediaWikiUnitTestCase.php
tests/phpunit/bootstrap.php

index 3f0fc7a..43a333c 100644 (file)
@@ -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 ];
                }
        }
 
index 10348d4..a7f0c09 100644 (file)
@@ -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;