aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/MediaWikiUnitTestCase.php
diff options
context:
space:
mode:
authorKosta Harlan <kharlan@wikimedia.org>2019-09-06 11:43:39 +0200
committerKosta Harlan <kharlan@wikimedia.org>2019-09-06 11:43:39 +0200
commit9878abd0c30b1832324e029430634cfdb18e7276 (patch)
treedd575c98dc38f98fd06c85c61db577a7e22f4a27 /tests/phpunit/MediaWikiUnitTestCase.php
parent62ef2c1e563ba5b60aac3fd5f0967ca381def0d7 (diff)
downloadmediawikicore-9878abd0c30b1832324e029430634cfdb18e7276.tar.gz
mediawikicore-9878abd0c30b1832324e029430634cfdb18e7276.zip
Unit tests: Whitelist global so LoggerFactory doesn't explode
Bug: T87781 Change-Id: I78ef16ac3b9efa7059905c44c234065aa68db680
Diffstat (limited to 'tests/phpunit/MediaWikiUnitTestCase.php')
-rw-r--r--tests/phpunit/MediaWikiUnitTestCase.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/phpunit/MediaWikiUnitTestCase.php b/tests/phpunit/MediaWikiUnitTestCase.php
index 3f876ae4aaca..76e8f7df9e4e 100644
--- a/tests/phpunit/MediaWikiUnitTestCase.php
+++ b/tests/phpunit/MediaWikiUnitTestCase.php
@@ -37,6 +37,25 @@ abstract class MediaWikiUnitTestCase extends TestCase {
private static $originalGlobals;
private static $unitGlobals;
+ /**
+ * Whitelist of globals to allow in MediaWikiUnitTestCase.
+ *
+ * Please, keep this list to the bare minimum.
+ *
+ * @return string[]
+ */
+ private static function getGlobalsWhitelist() {
+ return [
+ // The autoloader may change between bootstrap and the first test,
+ // so (lazily) capture these here instead.
+ 'wgAutoloadClasses',
+ 'wgAutoloadLocalClasses',
+ // Need for LoggerFactory. Default is NullSpi.
+ 'wgMWLoggerDefaultSpi',
+ 'wgAutoloadAttemptLowercase'
+ ];
+ }
+
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
@@ -56,12 +75,10 @@ abstract class MediaWikiUnitTestCase extends TestCase {
}
self::$unitGlobals =& TestSetup::$bootstrapGlobals;
- // The autoloader may change between bootstrap and the first test,
- // so (lazily) capture these here instead.
- self::$unitGlobals['wgAutoloadClasses'] =& $GLOBALS['wgAutoloadClasses'];
- self::$unitGlobals['wgAutoloadLocalClasses'] =& $GLOBALS['wgAutoloadLocalClasses'];
- // This value should always be true.
- self::$unitGlobals['wgAutoloadAttemptLowercase'] = true;
+
+ foreach ( self::getGlobalsWhitelist() as $global ) {
+ self::$unitGlobals[ $global ] =& $GLOBALS[ $global ];
+ }
// Would be nice if we coud simply replace $GLOBALS as a whole,
// but unsetting or re-assigning that breaks the reference of this magic