+ if ( stripos( $reflection->getFilename(), "${dirSeparator}unit${dirSeparator}" ) === false ) {
+ self::fail( 'This unit test needs to be in "tests/phpunit/unit"!' );
+ }
+
+ if ( defined( 'HHVM_VERSION' ) ) {
+ // There are a number of issues we encountered in trying to make this
+ // work on HHVM. Specifically, once an MediaWikiIntegrationTestCase executes
+ // before us, the original globals go missing. This might have to do with
+ // one of the non-unit tests passing GLOBALS somewhere and causing HHVM
+ // to get confused somehow.
+ return;
+ }
+
+ self::$unitGlobals =& TestSetup::$bootstrapGlobals;
+
+ foreach ( self::getGlobalsWhitelist() as $global ) {
+ self::$unitGlobals[ $global ] =& $GLOBALS[ $global ];
+ }
+
+ // Would be nice if we coud simply replace $GLOBALS as a whole,
+ // but unsetting or re-assigning that breaks the reference of this magic
+ // variable. Thus we have to modify it in place.
+ self::$originalGlobals = [];
+ foreach ( $GLOBALS as $key => $_ ) {
+ // Stash current values
+ self::$originalGlobals[$key] =& $GLOBALS[$key];
+
+ // Remove globals not part of the snapshot (see bootstrap.php, phpunit.php).
+ // Support: HHVM (avoid self-ref)
+ if ( $key !== 'GLOBALS' && !array_key_exists( $key, self::$unitGlobals ) ) {
+ unset( $GLOBALS[$key] );
+ }
+ }
+ // Restore values from the early snapshot
+ // Not by ref because tests must not be able to modify the snapshot.
+ foreach ( self::$unitGlobals as $key => $value ) {
+ $GLOBALS[ $key ] = $value;