feat(test/commen): add helpers for SERVER manipulating

master
dufraissejeremy 2 years ago
parent efad1f8b92
commit b6a2a22389
  1. 38
      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;
}
}
}
Loading…
Cancel
Save