From cc5cc79148e1b0a6381bbf7bac7c77cff6c78425 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 5 Sep 2012 15:04:07 +0200 Subject: [PATCH] Restore (some) globals after each test Change-Id: I5fbf777c2bd4b1f88ba76d5cc42ad6df2eee4a9c --- tests/phpunit/MediaWikiTestCase.php | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 3debb35055..202bd8ffd5 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -14,6 +14,16 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected $reuseDB = false; protected $tablesUsed = array(); // tables with data + protected $restoreGlobals = array( // global variables to restore for each test + 'wgLang', + 'wgContLang', + 'wgLanguageCode', + 'wgUser', + 'wgTitle', + ); + + private $savedGlobals = array(); + private static $dbSetup = false; /** @@ -114,7 +124,21 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { return $fname; } - protected function tearDown() { + protected function setup() { + parent::setup(); + + foreach ( $this->restoreGlobals as $var ) { + $v = $GLOBALS[ $var ]; + + if ( is_object( $v ) || is_array( $v ) ) { + $v = clone $v; + } + + $this->savedGlobals[ $var ] = $v; + } + } + + protected function teardown() { // Cleaning up temporary files foreach ( $this->tmpfiles as $fname ) { if ( is_file( $fname ) || ( is_link( $fname ) ) ) { @@ -131,7 +155,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } - parent::tearDown(); + // restore saved globals + foreach ( $this->savedGlobals as $k => $v ) { + $GLOBALS[ $k ] = $v; + } + + parent::teardown(); } function dbPrefix() { -- 2.20.1