Page MenuHomePhabricator

MediaWikiUnitTestCase clears globals belonging to the PHPUnit framework
Closed, ResolvedPublic

Description

While investigating T420009 I noticed an issue where, when using process isolation, PHPUnit was unable to run its bootstrap in the child process because the internal global variable __PHPUNIT_BOOTSTRAP was unset. I found out that PHPUnit did set the variable correctly upon initializing, but then our MediaWikiUnitTestCase::mediaWikiSetUpBeforeClass would mercilessly unset it like any other MW global. The same issue affects every internal PHPUnit global (such as __PHPUNIT_CONFIGURATION_FILE and __PHPUNIT_ISOLATION_EXCLUDE_LIST), but I'm not sure whether it has noticeable consequences when not using process isolation.

The setup code relies on a snapshot of the $GLOBALS array captured at the end of bootstrap.php to exclude likely-not-MediaWiki globals, such as PHP superglobals. So, it looks like everything works correctly today for those, as well as __composer_autoload_files. However, PHPUnit defines its internal globals after loading the bootstrap, so they are not snapshotted, and instead they are unset.

Event Timeline

Change #1354171 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] tests: don't unset non-MediaWiki globals in MediaWikiUnitTestCase

https://gerrit.wikimedia.org/r/1354171

Change #1354171 merged by jenkins-bot:

[mediawiki/core@master] tests: never unset non-MediaWiki globals in MediaWikiUnitTestCase

https://gerrit.wikimedia.org/r/1354171