From: daniel Date: Wed, 5 Sep 2012 13:04:07 +0000 (+0200) Subject: Restore (some) globals after each test X-Git-Tag: 1.31.0-rc.0~22097^2^2~29 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=cc5cc79148e1b0a6381bbf7bac7c77cff6c78425;p=lhc%2Fweb%2Fwiklou.git Restore (some) globals after each test Change-Id: I5fbf777c2bd4b1f88ba76d5cc42ad6df2eee4a9c --- 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() {