From 6140d94f450994eda761608041a2b204b372ad74 Mon Sep 17 00:00:00 2001 From: Kosta Harlan Date: Wed, 10 Jul 2019 13:20:00 -0400 Subject: [PATCH] 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 --- tests/phpunit/MediaWikiUnitTestCase.php | 4 ++-- tests/phpunit/bootstrap.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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; -- 2.20.1