X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiUnitTestCase.php;h=3f0fc7a55da5e8425ff8147819abce849f09dbac;hb=d23af35764bc7a5f223852d25baf554f1ae8f944;hp=06f0c9cd01aa660268429f254cc71b7a7a501a28;hpb=52ea095f2c0b874939dc6489a7143f03717b30eb;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiUnitTestCase.php b/tests/phpunit/MediaWikiUnitTestCase.php index 06f0c9cd01..3f0fc7a55d 100644 --- a/tests/phpunit/MediaWikiUnitTestCase.php +++ b/tests/phpunit/MediaWikiUnitTestCase.php @@ -30,4 +30,27 @@ use PHPUnit\Framework\TestCase; abstract class MediaWikiUnitTestCase extends TestCase { use PHPUnit4And6Compat; use MediaWikiCoversValidator; + + private $unitGlobals = []; + + protected function setUp() { + parent::setUp(); + $reflection = new ReflectionClass( $this ); + if ( strpos( $reflection->getFilename(), '/unit/' ) === false ) { + $this->fail( 'This unit test needs to be in "tests/phpunit/unit" !' ); + } + $this->unitGlobals = $GLOBALS; + unset( $GLOBALS ); + $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 ]; + } + } + + protected function tearDown() { + $GLOBALS = $this->unitGlobals; + parent::tearDown(); + } }