clean up demo code from testsuite needs
authorgggeek <giunta.gaetano@gmail.com>
Sat, 26 Nov 2022 11:22:49 +0000 (11:22 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 26 Nov 2022 11:22:49 +0000 (11:22 +0000)
28 files changed:
debugger/action.php
debugger/controller.php
debugger/index.php
demo/client/_append.php [deleted file]
demo/client/_prepend.php
demo/client/agesort.php
demo/client/getstatename.php
demo/client/introspect.php
demo/client/mail.php
demo/client/parallel.php
demo/client/proxy.php
demo/client/which.php
demo/client/wrap.php
demo/server/_append.php [deleted file]
demo/server/_prepend.php
demo/server/discuss.php
demo/server/proxy.php
demo/server/server.php
demo/vardemo.php
phpunit.xml.dist
tests/4ClientTest.php
tests/5ServerTest.php
tests/6HTTPTest.php
tests/7DemofilesTest.php
tests/8DebuggerTest.php
tests/9ExtraFilesTest.php
tests/ci/config/apache_vhost
tests/index.php [new file with mode: 0644]

index 9dacf15..7e35a22 100644 (file)
@@ -9,8 +9,6 @@
  * @todo be smarter in creating client stub for proxy/auth cases: only set appropriate property of client obj
  **/
 
-if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_prepend.php";
-
 header('Content-Type: text/html; charset=utf-8');
 
 ?>
@@ -565,4 +563,3 @@ if ($action) {
 ?>
 </body>
 </html>
-<?php if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_append.php"; ?>
index 1fcfea9..1501ac0 100644 (file)
@@ -14,8 +14,6 @@
  * @todo if js libs are not available, do not try to load them
  **/
 
-if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_prepend.php";
-
 // Make sure we set the correct charset type for output, so that we can display all characters
 header('Content-Type: text/html; charset=utf-8');
 
@@ -361,4 +359,3 @@ $editorlibs = (defined('JSXMLRPC_PATH') ? JSXMLRPC_PATH : '../..') . '/jsxmlrpc/
 </form>
 </body>
 </html>
-<?php if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_append.php"; ?>
index 7da4408..2e718d4 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_prepend.php";
-
 $query = '';
 if (isset($_GET['run'])) {
     $path = parse_url($_GET['run']);
@@ -23,4 +21,3 @@ if (isset($_GET['run'])) {
     <frame name="frmaction" src="action.php" marginwidth="0" marginheight="0" frameborder="0"/>
 </frameset>
 </html>
-<?php if (getenv('TESTMODE') === 'true') require_once __DIR__ . "/../demo/server/_append.php"; ?>
diff --git a/demo/client/_append.php b/demo/client/_append.php
deleted file mode 100644 (file)
index e235edf..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-// Out-of-band information: let the client manipulate the page operations.
-// We do this to help the testsuite script: do not reproduce in production!
-if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
-    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/append.php";
-}
index c29d7ec..61ef17d 100644 (file)
@@ -9,10 +9,6 @@ if (isset($_GET['showSource']) && $_GET['showSource']) {
     die();
 }
 
-// Make errors visible
-ini_set('display_errors', true);
-error_reporting(E_ALL);
-
 // Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
 include_once __DIR__ . '/../../src/Autoloader.php';
 PhpXmlRpc\Autoloader::register();
@@ -24,18 +20,6 @@ if (isset($_SERVER['HTTPSERVER'])) {
     define('XMLRPCSERVER', 'http://gggeek.altervista.org/sw/xmlrpc/demo/server/server.php');
 }
 
-// Out-of-band information: let the client manipulate the page operations.
-// We do this to help the testsuite script: do not reproduce in production!
-if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
-    $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = '/tmp/phpxmlrpc_coverage';
-    if (!is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
-        mkdir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']);
-        chmod($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], 0777);
-    }
-
-    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
-}
-
 // A helper for cli vs web output:
 function output($text)
 {
index 6b7be6a..c3384c3 100644 (file)
@@ -61,5 +61,3 @@ if (!$resp->faultCode()) {
 }
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
index 89b56cd..2f7df37 100644 (file)
@@ -40,5 +40,3 @@ output("<form action=\"getstatename.php\" method=\"POST\">
 <p>Enter a state number to query its name</p>");
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
index b4a0dca..b5fe336 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 require_once __DIR__ . "/_prepend.php";
 
 output('<html lang="en">
@@ -84,5 +83,3 @@ if ($resp->faultCode()) {
 }
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
index cd726b5..06f1db8 100644 (file)
@@ -56,5 +56,3 @@ output('
 </body>
 </html>
 ');
-
-require_once __DIR__ . "/_append.php";
index ace50e7..db302a1 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 require_once __DIR__ . "/_prepend.php";
 
 use PhpXmlRpc\Encoder;
@@ -122,5 +121,3 @@ $t = microtime(true);
 $resp = $client->send($reqs);
 $t = microtime(true) - $t;
 echo "Multicall send: $t secs\n";
-
-require_once __DIR__ . "/_append.php";
index 8e89e81..12b0a15 100644 (file)
@@ -76,5 +76,3 @@ $stateName = $proxy->getStateName($stateNo);
 output("State $stateNo is ".htmlspecialchars($stateName));
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
index 23a08b3..21eb83b 100644 (file)
@@ -29,5 +29,3 @@ if (!$resp->faultCode()) {
 }
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
index d752349..84ffdb8 100644 (file)
@@ -52,5 +52,3 @@ if ($resp->faultCode()) {
 }
 
 output("</body></html>\n");
-
-require_once __DIR__ . "/_append.php";
diff --git a/demo/server/_append.php b/demo/server/_append.php
deleted file mode 100644 (file)
index da249b3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-// Out-of-band information: let the client manipulate the server operations.
-// We do this to help the testsuite script: do not reproduce in production!
-if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
-    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/append.php";
-}
index 476b702..98de7fb 100644 (file)
@@ -3,10 +3,6 @@
  * Hackish code used to make the demos both viewable as source, runnable, and viewable as html
  */
 
-// Make errors visible
-ini_set('display_errors', true);
-error_reporting(E_ALL);
-
 if (isset($_GET['showSource']) && $_GET['showSource']) {
     $file = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file'];
     highlight_file($file);
@@ -16,15 +12,3 @@ if (isset($_GET['showSource']) && $_GET['showSource']) {
 // Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
 include_once __DIR__ . '/../../src/Autoloader.php';
 PhpXmlRpc\Autoloader::register();
-
-// Out-of-band information: let the client manipulate the server operations.
-// We do this to help the testsuite script: do not reproduce in production!
-if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
-    $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = '/tmp/phpxmlrpc_coverage';
-    if (!is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
-        mkdir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']);
-        chmod($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], 0777);
-    }
-
-    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
-}
index 08058cd..f5e93c7 100644 (file)
@@ -106,5 +106,3 @@ $srv = new PhpXmlRpc\Server(array(
         "docstring" => $getComments_doc,
     ),
 ));
-
-require_once __DIR__ . "/_append.php";
index f72a835..d70bf13 100644 (file)
@@ -89,5 +89,3 @@ $server = new PhpXmlRpc\Server(
         ),
     )
 );
-
-require_once __DIR__ . "/_append.php";
index a40a69d..41c401c 100644 (file)
@@ -120,5 +120,3 @@ if (isset($_GET['FORCE_AUTH'])) {
 
 $s->service();
 // That should do all we need!
-
-require_once __DIR__ . "/_append.php";
index 0390f85..ac7e678 100644 (file)
@@ -92,5 +92,3 @@ output("Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($t
 output("</pre>\n");
 
 output('</body></html>');
-
-require_once __DIR__ . "/client/_append.php";
index a4e4a19..555c4fc 100644 (file)
@@ -9,7 +9,6 @@
             <exclude>
                 <directory>./build</directory>
                 <directory>./doc</directory>
-                <directory>./extras</directory>
                 <directory>./tests</directory>
                 <directory>./vendor</directory>
                 <file>./pakefile.php</file>
index a2942b4..ec3ad76 100644 (file)
@@ -89,7 +89,7 @@ class ClientTest extends PhpXmlRpc_PolyfillTestCase
             $this->client->port = $server[1];
         }
         $this->client->server = $server[0];
-        $this->client->path = $this->args['HTTPURI'];
+        $this->client->path = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
 
         $r = $this->client->send($m, 5, 'http11');
         $this->assertEquals(0, $r->faultCode());
index 3db7b8f..f91b41a 100644 (file)
@@ -95,18 +95,19 @@ class ServerTest extends PhpXmlRpc_PolyfillTestCase
     {
         $this->args = argParser::getArgs();
 
+        $uri = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
         $server = explode(':', $this->args['HTTPSERVER']);
         if (count($server) > 1) {
-            $this->client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
+            $this->client = new xmlrpc_client($uri, $server[0], $server[1]);
         } else {
-            $this->client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
+            $this->client = new xmlrpc_client($uri, $this->args['HTTPSERVER']);
         }
 
         $this->client->setDebug($this->args['DEBUG']);
         $this->client->request_compression = $this->request_compression;
         $this->client->accepted_compression = $this->accepted_compression;
 
-        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace('/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI']);
 
         if ($this->args['DEBUG'] == 1)
             ob_start();
index e737f81..6880a0c 100644 (file)
@@ -465,7 +465,7 @@ class HTTPTest extends ServerTest
     {
         if ($this->expectHttp2) {
             $hr = $r->httpResponse();
-            $this->assertEquals("2", $hr['protocol_version']);
+            $this->assertEquals("2", @$hr['protocol_version']);
         } else {
 
         }
index 22334db..b387ba6 100644 (file)
@@ -11,31 +11,31 @@ class DemoFilesTest extends PhpXmlRpc_WebTestCase
     {
         $this->args = argParser::getArgs();
 
-        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/demo/', $this->args['HTTPURI'] );
+        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
 
-        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
     }
 
     public function testAgeSort()
     {
-        $page = $this->request('client/agesort.php');
+        $page = $this->request('?demo=client/agesort.php');
     }
 
     public function testGetStateName()
     {
-        $page = $this->request('client/getstatename.php');
-        $page = $this->request('client/getstatename.php', 'POST', array('stateno' => '1'));
+        $page = $this->request('?demo=client/getstatename.php');
+        $page = $this->request('?demo=client/getstatename.php', 'POST', array('stateno' => '1'));
     }
 
     public function testIntrospect()
     {
-        $page = $this->request('client/introspect.php');
+        $page = $this->request('?demo=client/introspect.php');
     }
 
     public function testMail()
     {
-        $page = $this->request('client/mail.php');
-        $page = $this->request('client/mail.php', 'POST', array(
+        $page = $this->request('?demo=client/mail.php');
+        $page = $this->request('?demo=client/mail.php', 'POST', array(
             "mailto" => '',
             "mailsub" => '',
             "mailmsg" => '',
@@ -47,28 +47,28 @@ class DemoFilesTest extends PhpXmlRpc_WebTestCase
 
     public function testParallel()
     {
-        $page = $this->request('client/parallel.php');
+        $page = $this->request('?demo=client/parallel.php');
     }
 
     public function testProxy()
     {
-        $page = $this->request('client/proxy.php', 'GET', null, true);
+        $page = $this->request('?demo=client/proxy.php', 'GET', null, true);
     }
 
     public function testWhich()
     {
-        $page = $this->request('client/which.php');
+        $page = $this->request('?demo=client/which.php');
     }
 
     public function testWrap()
     {
-        $page = $this->request('client/wrap.php');
+        $page = $this->request('?demo=client/wrap.php');
     }
 
     public function testDiscussServer()
     {
         /// @todo add a couple of proper xmlrpc calls, too
-        $page = $this->request('server/discuss.php');
+        $page = $this->request('?demo=server/discuss.php');
         $this->assertStringContainsString('<name>faultCode</name>', $page);
         $this->assertRegexp('#<int>10(5|3)</int>#', $page);
     }
@@ -76,7 +76,7 @@ class DemoFilesTest extends PhpXmlRpc_WebTestCase
     public function testProxyServer()
     {
         /// @todo add a couple of proper xmlrpc calls, too
-        $page = $this->request('server/proxy.php');
+        $page = $this->request('?demo=server/proxy.php');
         $this->assertStringContainsString('<name>faultCode</name>', $page);
         $this->assertRegexp('#<int>10(5|3)</int>#', $page);
     }
index 779ad47..8756471 100644 (file)
@@ -8,19 +8,19 @@ class DebuggerTest extends PhpXmlRpc_WebTestCase
     {
         $this->args = argParser::getArgs();
 
-        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/debugger/', $this->args['HTTPURI'] );
+        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
 
-        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
     }
 
     public function testIndex()
     {
-        $page = $this->request('index.php');
+        $page = $this->request('?debugger=index.php');
     }
 
     public function testController()
     {
-        $page = $this->request('controller.php');
+        $page = $this->request('?debugger=controller.php');
     }
 
     /**
@@ -32,6 +32,6 @@ class DebuggerTest extends PhpXmlRpc_WebTestCase
      */
     public function testAction()
     {
-        $page = $this->request('action.php');
+        $page = $this->request('?debugger=action.php');
     }
 }
index a88bace..05df2d6 100644 (file)
@@ -12,30 +12,23 @@ class ExtraFilesTest extends PhpXmlRpc_WebTestCase
     {
         $this->args = argParser::getArgs();
 
-        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/extras/', $this->args['HTTPURI'] );
+        $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
 
-        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
     }
 
-    /**
-     * @todo collect code coverage for this...
-     */
     public function testBenchmark()
     {
-        $page = $this->request('benchmark.php');
+        $page = $this->request('?extras=benchmark.php');
     }
 
-    /**
-     * @todo collect code coverage for this...
-     */
     public function testVerifyCompat()
     {
-        $page = $this->request('verify_compat.php');
+        $page = $this->request('?extras=verify_compat.php');
     }
 
     public function testVarDemo()
     {
-        $this->baseUrl = str_replace('/extras/', '/demo/', $this->baseUrl);
-        $page = $this->request('vardemo.php');
+        $page = $this->request('?demo=vardemo.php');
     }
 }
index 4cb918b..9852f68 100644 (file)
@@ -20,7 +20,6 @@
 
   # Env vars used by the test code, which we get from the environment
   SetEnv HTTPSERVER ${HTTPSERVER}
-  SetEnv TESTMODE true
 
   <Directory "${TESTS_ROOT_DIR}">
     Options FollowSymLinks MultiViews
@@ -52,7 +51,6 @@
 
   # Env vars used by the test code, which we get from the environment
   SetEnv HTTPSERVER ${HTTPSERVER}
-  SetEnv TESTMODE true
 
   <Directory "${TESTS_ROOT_DIR}">
     Options FollowSymLinks MultiViews
diff --git a/tests/index.php b/tests/index.php
new file mode 100644 (file)
index 0000000..e979612
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+// File accessed by http requests as part of the test suite, enabling testing of demo, debugger, extras files.
+// It triggers generation of code-coverage information
+
+// Make errors visible
+ini_set('display_errors', true);
+error_reporting(E_ALL);
+
+// Out-of-band information: let the client manipulate the page operations
+if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
+    $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = '/tmp/phpxmlrpc_coverage';
+    if (!is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
+        mkdir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']);
+        chmod($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], 0777);
+    }
+
+    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
+}
+
+$targetFile = null;
+$rootDir = dirname(__DIR__);
+if (isset($_GET['debugger'])) {
+    if (strpos(realpath($rootDir.'/debugger/'.$_GET['debugger']), realpath($rootDir.'/debugger/')) === 0) {
+        $targetFile = realpath($rootDir.'/debugger/'.$_GET['debugger']);
+    }
+} elseif (isset($_GET['demo'])) {
+    if (strpos(realpath($rootDir.'/demo/'.$_GET['demo']), realpath($rootDir.'/demo/')) === 0) {
+        $targetFile = realpath($rootDir.'/demo/'.$_GET['demo']);
+    }
+} elseif (isset($_GET['extras'])) {
+    if (strpos(realpath($rootDir.'/extras/'.$_GET['extras']), realpath($rootDir.'/extras/')) === 0) {
+        $targetFile = realpath($rootDir.'/extras/'.$_GET['extras']);
+    }
+}
+if ($targetFile) {
+    include $targetFile;
+}
+
+if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
+    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/append.php";
+}