Merge "Stash global only once per test case."
authorNikerabbit <niklas.laxstrom@gmail.com>
Mon, 29 Oct 2012 12:15:37 +0000 (12:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 29 Oct 2012 12:15:37 +0000 (12:15 +0000)
1  2 
tests/phpunit/MediaWikiTestCase.php

@@@ -220,15 -220,22 +220,22 @@@ abstract class MediaWikiTestCase extend
         *  if an array is given as first argument).
         */
        protected function setMwGlobals( $pairs, $value = null ) {
-               if ( !is_array( $pairs ) ) {
-                       $key = $pairs;
-                       $this->mwGlobals[$key] = $GLOBALS[$key];
-                       $GLOBALS[$key] = $value;
-               } else {
-                       foreach ( $pairs as $key => $value ) {
+               // Normalize (string, value) to an array
+               if( is_string( $pairs ) ) {
+                       $pairs = array( $pairs => $value );
+               }
+               foreach ( $pairs as $key => $value ) {
+                       // NOTE: make sure we only save the global once or a second call to
+                       // setMwGlobals() on the same global would override the original
+                       // value.
+                       if ( !array_key_exists( $key, $this->mwGlobals ) ) {
                                $this->mwGlobals[$key] = $GLOBALS[$key];
-                               $GLOBALS[$key] = $value;
                        }
+                       // Override the global
+                       $GLOBALS[$key] = $value;
                }
        }
  
                                throw new MWException( "MW global $name is not an array." );
                        }
  
 -                      //NOTE: do not use array_merge, it screws up for numeric keys.
 +                      // NOTE: do not use array_merge, it screws up for numeric keys.
                        $merged = $GLOBALS[$name];
                        foreach ( $values as $k => $v ) {
                                $merged[$k] = $v;