Merge "Restore the ability to set $wgResourceModuleSkinStyles for 'oojs-ui-core.styles'"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index bc9f97c..df3d568 100644 (file)
@@ -737,6 +737,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                        $GLOBALS[$globalKey] instanceof FauxRequest
                                ) {
                                        $this->mwGlobals[$globalKey] = clone $GLOBALS[$globalKey];
+                               } elseif ( $this->containsClosure( $GLOBALS[$globalKey] ) ) {
+                                       // Serializing Closure only gives a warning on HHVM while
+                                       // it throws an Exception on Zend.
+                                       // Workaround for https://github.com/facebook/hhvm/issues/6206
+                                       $this->mwGlobals[$globalKey] = $GLOBALS[$globalKey];
                                } else {
                                        try {
                                                $this->mwGlobals[$globalKey] = unserialize( serialize( $GLOBALS[$globalKey] ) );
@@ -748,6 +753,28 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                }
        }
 
+       /**
+        * @param mixed $var
+        * @param int $maxDepth
+        *
+        * @return bool
+        */
+       private function containsClosure( $var, $maxDepth = 15 ) {
+               if ( $var instanceof Closure ) {
+                       return true;
+               }
+               if ( !is_array( $var ) || $maxDepth === 0 ) {
+                       return false;
+               }
+
+               foreach ( $var as $value ) {
+                       if ( $this->containsClosure( $value, $maxDepth - 1 ) ) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
        /**
         * Merges the given values into a MW global array variable.
         * Useful for setting some entries in a configuration array, instead of