Merge "DatabaseSqlite::insert: Fix affected row count"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index dfd4309..287d28c 100644 (file)
@@ -100,6 +100,14 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         */
        private $mwGlobalsToUnset = [];
 
+       /**
+        * Holds original values of ini settings to be restored
+        * in tearDown().
+        * @see setIniSettings()
+        * @var array
+        */
+       private $iniSettings = [];
+
        /**
         * Holds original loggers which have been replaced by setLogger()
         * @var LoggerInterface[]
@@ -573,6 +581,9 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                foreach ( $this->mwGlobalsToUnset as $value ) {
                        unset( $GLOBALS[$value] );
                }
+               foreach ( $this->iniSettings as $name => $value ) {
+                       ini_set( $name, $value );
+               }
                if (
                        array_key_exists( 'wgExtraNamespaces', $this->mwGlobals ) ||
                        in_array( 'wgExtraNamespaces', $this->mwGlobalsToUnset )
@@ -711,7 +722,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * touch.
         */
        private function doSetMwGlobals( $pairs, $value = null ) {
-               $this->stashMwGlobals( array_keys( $pairs ) );
+               $this->doStashMwGlobals( array_keys( $pairs ) );
 
                foreach ( $pairs as $key => $value ) {
                        $GLOBALS[$key] = $value;
@@ -722,6 +733,18 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                }
        }
 
+       /**
+        * Set an ini setting for the duration of the test
+        * @param string $name Name of the setting
+        * @param string $value Value to set
+        * @since 1.32
+        */
+       protected function setIniSetting( $name, $value ) {
+               $original = ini_get( $name );
+               $this->iniSettings[$name] = $original;
+               ini_set( $name, $value );
+       }
+
        /**
         * Must be called whenever namespaces are changed, e.g., $wgExtraNamespaces is altered.
         * Otherwise old namespace data will lurk and cause bugs.
@@ -785,8 +808,14 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         *       call overrideMwServices().
         *
         * @since 1.23
+        * @deprecated since 1.32, use setMwGlobals() and don't alter globals directly
         */
        protected function stashMwGlobals( $globalKeys ) {
+               wfDeprecated( __METHOD__, '1.32' );
+               $this->doStashMwGlobals( $globalKeys );
+       }
+
+       private function doStashMwGlobals( $globalKeys ) {
                if ( is_string( $globalKeys ) ) {
                        $globalKeys = [ $globalKeys ];
                }
@@ -1063,17 +1092,18 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
        public function setGroupPermissions( $newPerms, $newKey = null, $newValue = null ) {
                global $wgGroupPermissions;
 
-               $this->stashMwGlobals( 'wgGroupPermissions' );
-
                if ( is_string( $newPerms ) ) {
                        $newPerms = [ $newPerms => [ $newKey => $newValue ] ];
                }
 
+               $newPermissions = $wgGroupPermissions;
                foreach ( $newPerms as $group => $permissions ) {
                        foreach ( $permissions as $key => $value ) {
-                               $wgGroupPermissions[$group][$key] = $value;
+                               $newPermissions[$group][$key] = $value;
                        }
                }
+
+               $this->setMwGlobals( 'wgGroupPermissions', $newPermissions );
        }
 
        /**