diff --git a/tests/Common.php b/tests/Common.php index 5008660..ca5d756 100644 --- a/tests/Common.php +++ b/tests/Common.php @@ -95,4 +95,42 @@ abstract class Common extends TestCase { $_SERVER['HTTPS'] = null; // forced } } + + /** + * save previous $_SERVER in $GLOBALS if existing + */ + public function saveSERVER() + { + if (!isset($GLOBALS['savedSERVER'])){ + $GLOBALS['savedSERVER'] = [ + 'saved' => false, + 'value' => null + ]; + } + if (!$GLOBALS['savedSERVER']['saved']){ + if (!isset($_SERVER)){ + $GLOBALS['savedSERVER']['value'] = null; + $GLOBALS['savedSERVER']['saved'] = true; + } else { + $GLOBALS['savedSERVER']['value'] = $_SERVER; + $GLOBALS['savedSERVER']['saved'] = true; + } + } + } + + /** + * revert previous $_SERVER in $GLOBALS if existing + */ + public function revertSERVER() + { + if (isset($GLOBALS['savedSERVER']['saved']) && $GLOBALS['savedSERVER']['saved']){ + if (is_null($GLOBALS['savedSERVER']['value'])){ + unset($_SERVER); + } else { + $_SERVER = $GLOBALS['savedSERVER']['value']; + } + $GLOBALS['savedSERVER']['saved'] = false; + $GLOBALS['savedSERVER']['value'] = null; + } + } } \ No newline at end of file