From b6a2a223898e50498b312e7fb1400f4de99e51d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Mon, 20 Mar 2023 08:51:54 +0100 Subject: [PATCH] feat(test/commen): add helpers for SERVER manipulating --- tests/Common.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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