Skip to content

Instantly share code, notes, and snippets.

@lolli42
Created March 5, 2014 20:18
Show Gist options
  • Save lolli42/9375718 to your computer and use it in GitHub Desktop.
Save lolli42/9375718 to your computer and use it in GitHub Desktop.
diff --git a/Composer/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php b/Composer/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php
index 2737985..baba04e 100644
--- a/Composer/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php
+++ b/Composer/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php
@@ -112,7 +112,7 @@ public static function backupGlobals(array $blacklist)
!in_array($key, $superGlobalArrays) &&
!in_array($key, $blacklist) &&
!$GLOBALS[$key] instanceof Closure) {
- self::$globals['GLOBALS'][$key] = serialize($GLOBALS[$key]);
+ self::$globals['GLOBALS'][$key] = $GLOBALS[$key];
}
}
}
@@ -138,16 +138,12 @@ public static function restoreGlobals(array $blacklist)
!in_array($key, $superGlobalArrays) &&
!in_array($key, $blacklist)) {
if (isset(self::$globals['GLOBALS'][$key])) {
- $GLOBALS[$key] = unserialize(
- self::$globals['GLOBALS'][$key]
- );
+ $GLOBALS[$key] = self::$globals['GLOBALS'][$key];
} else {
unset($GLOBALS[$key]);
}
}
}
-
- self::$globals = array();
}
protected static function backupSuperGlobalArray($superGlobalArray)
@sebastianbergmann
Copy link

This looks fishy. Have you tried disabling the backup of global state instead?

@lolli42
Copy link
Author

lolli42 commented Mar 6, 2014

Our tests rely on backupGlobals, we're manipulating stuff in GLOBALS a lot, the feature itself is very convenient for us.
But TYPO3 CMS puts lots of stuff into GLOBALS, for example some pretty big arrays. Serializing this all the time eats ~80% of unit test runtime, so our tests can be speed up by factor 5 if we suppress the serialization like done with the above patch.
The only drawback of not serializing is that manipulated objects in global scope can be changed by tests and are not correctly reconstituted again, but this is not an issue in our case.

Maybe we could have a phpunit setting to disable this serialization? I could come up with a patch, if you give green light for the idea, Sebastian.

@lolli42
Copy link
Author

lolli42 commented Mar 16, 2014

Meanwhile, this hack is obsolete for TYPO3 CMS core. We drastically reduced unit test bootstrap and the globals are much smaller now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment