tests and docs
authorgggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 09:44:24 +0000 (09:44 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 09:44:24 +0000 (09:44 +0000)
NEWS.md
tests/02ValueTest.php
tests/07ClientTest.php
tests/08ServerTest.php
tests/09HTTPTest.php

diff --git a/NEWS.md b/NEWS.md
index d191eaf..ba4c129 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -62,6 +62,9 @@
 * new: it is now possible to inject a custom logger into helper classes `Charset`, `Http`, `XMLParser`, inching a step
   closer to supporting DIC patterns
 
+* new: passing value -1 to `$client->setDebug` will avoid storing the full http response data in the returned Response
+  object when executing `call`. This could be useful in reducing memory usage for big responses
+
 * new: when calling `Wrapper::wrapXmlrpcMethod` and `wrapXmlrpcServer`, it is possible to pass 'throw_on_fault' as option
   to argument `$extraOptions`. This will make the generated function throw on http errors and xml-rpc faults instead of
   returning a Response object
@@ -78,9 +81,9 @@
 
 * improved: when calling `Client::multicall()`, the returned `Response` objects did not have any data in their `httpResponse`
 
-* improved: method `Helper\Date::iso8601Encode` now accepts a DateTime input beside a timestamp
+* new: method `Helper\Date::iso8601Encode` now accepts a DateTime input beside a timestamp
 
-* improved: method `Server::add_to_map` has acquired a 6th parameter: `$parametersType = false`
+* new: method `Server::add_to_map` has acquired a 6th parameter: `$parametersType = false`
 
 * improved: the `XMLParser` accepts more options in its constructor (see phpdocs for details)
 
index 6161d59..f7884bc 100644 (file)
@@ -137,6 +137,18 @@ class ValueTests extends PhpXmlRpc_PolyfillTestCase
         date_default_timezone_set($tz);
     }
 
+    /// @todo is this included in the above?
+    public function testDateTime()
+    {
+        $time = time();
+        $t1 = new xmlrpcval($time, 'dateTime.iso8601');
+        $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
+        $this->assertEquals($t1->serialize(), $t2->serialize());
+        $datetime = new DateTime();
+        $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
+        $this->assertEquals($t1->serialize(), $t3->serialize());
+    }
+
     public function testStructMemExists()
     {
         $v = new xmlrpcval(array('hello' => new xmlrpcval('world')), 'struct');
index a43b827..dd2ab40 100644 (file)
@@ -9,8 +9,7 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests involving the Client class.
- * So far: only tests requests sent to non-existing servers
+ * Tests involving the Client class (and no server).
  */
 class ClientTest extends PhpXmlRpc_PolyfillTestCase
 {
index e7979d6..40252d7 100644 (file)
@@ -12,7 +12,7 @@ use PHPUnit\Framework\TestResult;
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests which involve interaction between the client and the server.
+ * Tests which involve interaction with the server - carried out via the client.
  * They are run against the server found in demo/server.php.
  * Includes testing of (some of) the Wrapper class
  */
@@ -328,8 +328,7 @@ class ServerTest extends PhpXmlRpc_PolyfillTestCase
 
     public function testAddingDoubles()
     {
-        // note that rounding errors mean we
-        // keep precision to sensible levels here ;-)
+        // note that rounding errors mean we keep precision to sensible levels here ;-)
         $a = 12.13;
         $b = -23.98;
         $m = new xmlrpcmsg('examples.addtwodouble', array(
@@ -425,22 +424,6 @@ And turned it into nylon';
         }
     }
 
-    public function testDateTime()
-    {
-        $time = time();
-        $t1 = new xmlrpcval($time, 'dateTime.iso8601');
-        $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
-        $this->assertEquals($t1->serialize(), $t2->serialize());
-        if (class_exists('DateTime')) {
-            $datetime = new DateTime();
-            // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
-            if (is_callable(array($datetime, 'setTimestamp'))) {
-                $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
-                $this->assertEquals($t1->serialize(), $t3->serialize());
-            }
-        }
-    }
-
     public function testCountEntities()
     {
         $sendString = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
@@ -460,8 +443,9 @@ And turned it into nylon';
         }
     }
 
-    public function _multicall_msg($method, $params)
+    protected function _multicall_msg($method, $params)
     {
+        $struct = array();
         $struct['methodName'] = new xmlrpcval($method, 'string');
         $struct['params'] = new xmlrpcval($params, 'array');
 
@@ -688,7 +672,7 @@ And turned it into nylon';
 
     public function testCatchExceptions()
     {
-        // this tests for the server to catch exceptions with erro  code 0
+        // this tests for the server to catch exceptions with error code 0
         $m = new xmlrpcmsg('tests.raiseException', array(
             new xmlrpcval(0, 'int'),
         ));
@@ -1080,4 +1064,23 @@ And turned it into nylon';
             $this->assertEquals($v1, $v2);
         }
     }
+
+    public function testNegativeDebug()
+    {
+        $m = new xmlrpcmsg('examples.stringecho', array(
+            new xmlrpcval('hello world', 'string'),
+        ));
+        $v1 = $this->send($m, 0, true);
+        $h = $v1->httpResponse();
+        $this->assertEquals('200', $h['status_code']);
+        $this->assertNotEmpty($h['headers']);
+
+        $d = $this->client->debug;
+        $this->client->setDebug(-1);
+        $v2 = $this->send($m, 0, true);
+        $this->client->setDebug($d);
+        $h = $v2->httpResponse();
+        $this->assertEmpty($h['headers']);
+        $this->assertEmpty($h['raw_data']);
+    }
 }
index 52f1b85..58a0b52 100644 (file)
@@ -26,7 +26,7 @@ class HTTPTest extends ServerTest
         $unsafeMethods = array(
             'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments',
             'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
-            'testWrapInexistentUrl',
+            'testWrapInexistentUrl', 'testNegativeDebug'
         );
 
         $methods = array();