Catch Serialization Exception in MediaWikiTestCase
authoraddshore <addshorewiki@gmail.com>
Wed, 5 Mar 2014 19:50:20 +0000 (20:50 +0100)
committeraddshore <addshorewiki@gmail.com>
Wed, 5 Mar 2014 19:50:20 +0000 (20:50 +0100)
In the case that something is not serializable then
we should fall back and just set the value.

This is the case for Closures..
See
http://wikidata-jenkins.wmflabs.org/ci/job/wikidata-client-tests/748/console

Change-Id: Ib5f76932d60840a2f97671c134e18adc619974cd

tests/phpunit/MediaWikiTestCase.php

index 9ca1cab..4d64d05 100644 (file)
@@ -315,7 +315,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                // NOTE: we serialize then unserialize the value in case it is an object
                                // this stops any objects being passed by reference. We could use clone
                                // and if is_object but this does account for objects within objects!
-                               $this->mwGlobals[$key] = unserialize( serialize( $GLOBALS[$key] ) );
+                               try{
+                                       $this->mwGlobals[$key] = unserialize( serialize( $GLOBALS[$key] ) );
+                               }
+                               // NOTE; some things such as Closures are not serializable
+                               // in this case just set the value!
+                               catch( Exception $e ) {
+                                       $this->mwGlobals[$key] = $GLOBALS[$key];
+                               }
                        }
 
                        // Override the global