X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Fparse_args.php;h=712fa990a15869940e43b273a127f7ae77d5b7d5;hb=d20c6b4814808f6292298ae5cada12a7dd5b69eb;hp=6dc9b82b46ef3b7d9a5a1635ebe3d583c8ea365c;hpb=3cc4f1933ac0c298f99cb73eae19ba698d06f838;p=plcapi.git diff --git a/tests/parse_args.php b/tests/parse_args.php index 6dc9b82..712fa99 100644 --- a/tests/parse_args.php +++ b/tests/parse_args.php @@ -4,47 +4,50 @@ * Common parameter parsing for benchmark and tests scripts. * * @param integer DEBUG - * @param string LOCALSERVER - * @param string URI + * @param string HTTPSERVER + * @param string HTTPURI * @param string HTTPSSERVER - * @param string HTTPSSURI - * @param string PROXY - * @param string NOPROXY + * @param string HTTPSURI * @param bool HTTPSIGNOREPEER * @param int HTTPSVERIFYHOST * @param int SSLVERSION + * @param string PROXYSERVER * - * @copyright (C) 2007-2020 G. Giunta + * @copyright (C) 2007-2021 G. Giunta * @license code licensed under the BSD License: see file license.txt + * + * @todo rename both the class and the file. PhpXmlRpc_TestArgParser ? **/ class argParser { + /** + * @return array + */ public static function getArgs() { - global $argv; - + /// @todo should we prefix all test parameters with TESTS_ ? $args = array( 'DEBUG' => 0, - 'LOCALSERVER' => 'localhost', - 'HTTPSSERVER' => 'gggeek.ssl.altervista.org', - 'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php', + 'HTTPSERVER' => 'localhost', + 'HTTPURI' => null, + // now that we run tests in Docker by default, with a webserver set up for https, let's default to it + 'HTTPSSERVER' => 'localhost', + 'HTTPSURI' => null, + // example alternative: + //'HTTPSSERVER' => 'gggeek.altervista.org', + //'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php', 'HTTPSIGNOREPEER' => false, 'HTTPSVERIFYHOST' => 2, 'SSLVERSION' => 0, 'PROXYSERVER' => null, - 'NOPROXY' => false, - 'LOCALPATH' => __DIR__, + //'LOCALPATH' => __DIR__, ); - // check for command line vs web page input params + // check for command line (env vars) vs. web page input params if (!isset($_SERVER['REQUEST_METHOD'])) { - if (isset($argv)) { - foreach ($argv as $param) { - $param = explode('=', $param); - if (count($param) > 1) { - $pname = strtoupper(ltrim($param[0], '-')); - $$pname = $param[1]; - } + foreach($_SERVER as $key => $val) { + if (array_key_exists($key, $args)) { + $$key = $val; } } } else { @@ -56,32 +59,64 @@ class argParser if (isset($DEBUG)) { $args['DEBUG'] = intval($DEBUG); } - if (isset($LOCALSERVER)) { - $args['LOCALSERVER'] = $LOCALSERVER; + + if (isset($HTTPSERVER)) { + $args['HTTPSERVER'] = $HTTPSERVER; } else { if (isset($HTTP_HOST)) { - $args['LOCALSERVER'] = $HTTP_HOST; + $args['HTTPSERVER'] = $HTTP_HOST; } elseif (isset($_SERVER['HTTP_HOST'])) { - $args['LOCALSERVER'] = $_SERVER['HTTP_HOST']; + $args['HTTPSERVER'] = $_SERVER['HTTP_HOST']; } } + + if (!isset($HTTPURI) || $HTTPURI == '') { + // GUESTIMATE the url of local demo server + // play nice to php 4 and 5 in retrieving URL of server.php + /// @todo filter out query string from REQUEST_URI + /// @todo review this code... + if (isset($REQUEST_URI)) { + $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI); + $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI); + $HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI); + $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI); + } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) { + $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']); + $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI); + $HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI); + $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI); + } else { + $HTTPURI = '/demo/server/server.php'; + } + } + if ($HTTPURI[0] != '/') { + $HTTPURI = '/' . $HTTPURI; + } + $args['HTTPURI'] = $HTTPURI; + if (isset($HTTPSSERVER)) { $args['HTTPSSERVER'] = $HTTPSSERVER; } + + /// @todo if $HTTPSURI is unset, and HTTPSSERVER == localhost, use HTTPURI if (isset($HTTPSURI)) { $args['HTTPSURI'] = $HTTPSURI; } + if (isset($HTTPSIGNOREPEER)) { $args['HTTPSIGNOREPEER'] = (bool)$HTTPSIGNOREPEER; } + if (isset($HTTPSVERIFYHOST)) { $args['HTTPSVERIFYHOST'] = (int)$HTTPSVERIFYHOST; } + if (isset($SSLVERSION)) { $args['SSLVERSION'] = (int)$SSLVERSION; } - if (isset($PROXY)) { - $arr = explode(':', $PROXY); + + if (isset($PROXYSERVER)) { + $arr = explode(':', $PROXYSERVER); $args['PROXYSERVER'] = $arr[0]; if (count($arr) > 1) { $args['PROXYPORT'] = $arr[1]; @@ -89,35 +124,10 @@ class argParser $args['PROXYPORT'] = 8080; } } - // used to silence testsuite warnings about proxy code not being tested - if (isset($NOPROXY)) { - $args['NOPROXY'] = true; - } - if (!isset($URI)) { - // GUESTIMATE the url of local demo server - // play nice to php 3 and 4-5 in retrieving URL of server.php - /// @todo filter out query string from REQUEST_URI - if (isset($REQUEST_URI)) { - $URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI); - $URI = str_replace('/testsuite.php', '/server.php', $URI); - $URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI); - $URI = str_replace('/benchmark.php', '/server.php', $URI); - } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) { - $URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']); - $URI = str_replace('/testsuite.php', '/server.php', $URI); - $URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI); - $URI = str_replace('/benchmark.php', '/server.php', $URI); - } else { - $URI = '/demo/server/server.php'; - } - } - if ($URI[0] != '/') { - $URI = '/' . $URI; - } - $args['URI'] = $URI; - if (isset($LOCALPATH)) { - $args['LOCALPATH'] = $LOCALPATH; - } + + //if (isset($LOCALPATH)) { + // $args['LOCALPATH'] = $LOCALPATH; + //} return $args; }