From b6cd05cbe35539cc394877d2912fe9f48d58e49f Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 24 Jan 2023 09:44:24 +0000 Subject: [PATCH] tests and docs --- NEWS.md | 7 +++++-- tests/02ValueTest.php | 12 +++++++++++ tests/07ClientTest.php | 3 +-- tests/08ServerTest.php | 45 ++++++++++++++++++++++-------------------- tests/09HTTPTest.php | 2 +- 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/NEWS.md b/NEWS.md index d191eafa..ba4c1291 100644 --- 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) diff --git a/tests/02ValueTest.php b/tests/02ValueTest.php index 6161d595..f7884bcd 100644 --- a/tests/02ValueTest.php +++ b/tests/02ValueTest.php @@ -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'); diff --git a/tests/07ClientTest.php b/tests/07ClientTest.php index a43b827e..dd2ab402 100644 --- a/tests/07ClientTest.php +++ b/tests/07ClientTest.php @@ -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 { diff --git a/tests/08ServerTest.php b/tests/08ServerTest.php index e7979d64..40252d78 100644 --- a/tests/08ServerTest.php +++ b/tests/08ServerTest.php @@ -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>eassertEquals($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']); + } } diff --git a/tests/09HTTPTest.php b/tests/09HTTPTest.php index 52f1b855..58a0b52a 100644 --- a/tests/09HTTPTest.php +++ b/tests/09HTTPTest.php @@ -26,7 +26,7 @@ class HTTPTest extends ServerTest $unsafeMethods = array( 'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3', - 'testWrapInexistentUrl', + 'testWrapInexistentUrl', 'testNegativeDebug' ); $methods = array(); -- 2.47.0