fix(Test/Common): to be able to define all possible $_SERVER

master
dufraissejeremy 2 years ago
parent fdd6f50d46
commit efad1f8b92
  1. 23
      tests/Common.php

@ -30,10 +30,7 @@ abstract class Common extends TestCase {
string $pathInfo = '' string $pathInfo = ''
) )
{ {
if (is_file($filePath) && ( if (is_file($filePath)){
substr($shortScriptName,-1) == '/' ||
basename($shortScriptName) == basename($shortScriptName)
)){
if (!is_array($_SERVER) || $reset){ if (!is_array($_SERVER) || $reset){
$new = []; $new = [];
if (is_array($_SERVER)){ if (is_array($_SERVER)){
@ -57,9 +54,9 @@ abstract class Common extends TestCase {
: substr($documentRoot,0,-strlen(DIRECTORY_SEPARATOR)); : substr($documentRoot,0,-strlen(DIRECTORY_SEPARATOR));
$documentRootFull = $documentRootShort.DIRECTORY_SEPARATOR; $documentRootFull = $documentRootShort.DIRECTORY_SEPARATOR;
$scriptName = (substr($shortScriptName,-1) == '/') $scriptName = (basename($shortScriptName) == $fileName)
? $shortScriptName.$fileName ? $shortScriptName
: $shortScriptName; : $shortScriptName.((empty($shortScriptName) || substr($shortScriptName,-1) == '/') ? '' : '/').$fileName;
$hashPos = strpos($queryString,'#'); $hashPos = strpos($queryString,'#');
$queryStringWithoutHash = $queryStringWithoutHash =
@ -77,7 +74,17 @@ abstract class Common extends TestCase {
$_SERVER['PATH_INFO'] = $pathInfo; $_SERVER['PATH_INFO'] = $pathInfo;
$_SERVER['ORIG_PATH_INFO'] = $pathInfo; $_SERVER['ORIG_PATH_INFO'] = $pathInfo;
$_SERVER['PATH_TRANSLATED'] = $documentRootShort.$pathInfo; $_SERVER['PATH_TRANSLATED'] = $documentRootShort.$pathInfo;
$_SERVER['DOCUMENT_URI'] = $shortRequestUri.$pathInfo; if (substr($shortScriptName,-1) == '/'){
if (!empty($pathInfo) && substr($pathInfo,0,1) == '/'){
$_SERVER['DOCUMENT_URI'] = $shortScriptName.substr($pathInfo,1);
} else {
$_SERVER['DOCUMENT_URI'] = $shortScriptName.$pathInfo;
}
} else if (empty($pathInfo) || substr($pathInfo,0,1) == '/'){
$_SERVER['DOCUMENT_URI'] = $shortScriptName.$pathInfo;
} else {
$_SERVER['DOCUMENT_URI'] = $shortScriptName.'/'.$pathInfo;
}
$_SERVER['REQUEST_URI'] = $_SERVER['DOCUMENT_URI'].$queryStringWithoutHash; $_SERVER['REQUEST_URI'] = $_SERVER['DOCUMENT_URI'].$queryStringWithoutHash;
$_SERVER['DOCUMENT_ROOT'] = $documentRootShort; $_SERVER['DOCUMENT_ROOT'] = $documentRootShort;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // forced $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // forced

Loading…
Cancel
Save