fix legacy autoloading; add tests for it
authorgggeek <giunta.gaetano@gmail.com>
Wed, 22 Feb 2023 12:20:44 +0000 (12:20 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 22 Feb 2023 12:20:44 +0000 (12:20 +0000)
NEWS.md
demo/server/legacy.php [new file with mode: 0644]
lib/xmlrpc.inc
tests/13LegacyAPITest.php [new file with mode: 0644]
tests/legacy_loader_test.php [new file with mode: 0644]

diff --git a/NEWS.md b/NEWS.md
index 83180cd..c482c64 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
 ## XML-RPC for PHP version 4.10.1 - unreleased
 
+* fixed: class autoloading got broken in rel 4.10.0 for users of the legacy API (issue #111)
+
 * fixed: let the Server create Response objects whose class can be overridden by subclasses (this is required by the
   json-rpc server now that the `xml_header` method has been moved to the `Request` object)
 
diff --git a/demo/server/legacy.php b/demo/server/legacy.php
new file mode 100644 (file)
index 0000000..52f5b60
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Demo server for phpxmlrpc library - legacy (v3) API.
+ *
+ * It mimics server.php, but does not rely on other autoload mechanisms than the loading of xmlrpc.inc and xmlrpcs.inc
+ */
+
+require_once __DIR__ . "/../../lib/xmlrpc.inc";
+require_once __DIR__ . "/../../lib/xmlrpcs.inc";
+
+$signatures1 = include(__DIR__.'/methodProviders/functions.php');
+$signatures2 = include(__DIR__.'/methodProviders/interop.php');
+$signatures3 = include(__DIR__.'/methodProviders/validator1.php');
+$signatures = array_merge($signatures1, $signatures2, $signatures3);
+
+$s = new xmlrpc_server($signatures, false);
+$s->setDebug(3);
+$s->service();
index b558c5e..f15d82d 100644 (file)
@@ -62,16 +62,17 @@ include_once(__DIR__.'/../src/Exception/StateErrorException.php');
 include_once(__DIR__.'/../src/Exception/TypeErrorException.php');
 include_once(__DIR__.'/../src/Exception/ValueErrorException.php');
 include_once(__DIR__.'/../src/PhpXmlRpc.php');
+include_once(__DIR__.'/../src/Traits/CharsetEncoderAware.php');
+include_once(__DIR__.'/../src/Traits/LoggerAware.php');
+include_once(__DIR__.'/../src/Traits/DeprecationLogger.php');
+include_once(__DIR__.'/../src/Traits/ParserAware.php');
+include_once(__DIR__.'/../src/Traits/PayloadBearer.php');
 include_once(__DIR__.'/../src/Helper/Charset.php');
 include_once(__DIR__.'/../src/Helper/Date.php');
 include_once(__DIR__.'/../src/Helper/Http.php');
 include_once(__DIR__.'/../src/Helper/Interop.php');
 include_once(__DIR__.'/../src/Helper/Logger.php');
 include_once(__DIR__.'/../src/Helper/XMLParser.php');
-include_once(__DIR__.'/../src/Traits/CharsetEncoderAware.php');
-include_once(__DIR__.'/../src/Traits/LoggerAware.php');
-include_once(__DIR__.'/../src/Traits/DeprecationLogger.php');
-include_once(__DIR__.'/../src/Traits/ParserAware.php');
 include_once(__DIR__.'/../src/Value.php');
 include_once(__DIR__.'/../src/Request.php');
 include_once(__DIR__.'/../src/Response.php');
diff --git a/tests/13LegacyAPITest.php b/tests/13LegacyAPITest.php
new file mode 100644 (file)
index 0000000..4c5c636
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+include_once __DIR__ . '/ServerAwareTestCase.php';
+
+/**
+ * Long-term, this should replace all testing of the legacy API done via the main test-suite...
+ */
+class LegacyAPITest extends PhpXmlRpc_ServerAwareTestCase
+{
+    public function testLegacyLoader()
+    {
+        /// @todo pass on as cli args for the executed script all the args that are already parsed by now
+
+        exec('php ' . __DIR__ . '/legacy_loader_test.php', $out, $result);
+
+        /// @todo dump output if in debug mode or if test fails
+
+        $this->assertEquals(0, $result);
+    }
+}
diff --git a/tests/legacy_loader_test.php b/tests/legacy_loader_test.php
new file mode 100644 (file)
index 0000000..3a0773f
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * A test file designed to test the legacy API class-loading mechanism, ie. not using phpunit/composer's autoload_
+ */
+
+include_once __DIR__ . '/../lib/xmlrpc.inc';
+include_once __DIR__ . '/../lib/xmlrpcs.inc';
+
+include_once __DIR__ . '/parse_args.php';
+
+$args = argParser::getArgs();
+$baseurl = 'http://' . $args['HTTPSERVER'] . str_replace('/server.php', '/legacy.php', $args['HTTPURI']);
+
+$randId = uniqid();
+file_put_contents(sys_get_temp_dir() . '/phpunit_rand_id.txt', $randId);
+
+$client = new xmlrpc_client($baseurl);
+$client->setCookie('PHPUNIT_RANDOM_TEST_ID', $randId);
+
+$req = new xmlrpcmsg('system.listMethods', array());
+$resp = $client->send($req);
+if ($resp->faultCode() !== 0) {
+    throw new \Exception("system.listMethods returned fault " . $resp->faultCode());
+}
+
+unlink(sys_get_temp_dir() . '/phpunit_rand_id.txt');