tests reorg
authorgggeek <giunta.gaetano@gmail.com>
Wed, 30 Dec 2020 16:46:16 +0000 (16:46 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 30 Dec 2020 16:46:16 +0000 (16:46 +0000)
tests/0CharsetTest.php
tests/1ValueTest.php [new file with mode: 0644]
tests/2MessageTest.php [moved from tests/1ParsingBugsTest.php with 71% similarity]
tests/3EncoderTest.php [new file with mode: 0644]
tests/4ClientTest.php [moved from tests/2InvalidHostTest.php with 95% similarity]
tests/5ServerTest.php [moved from tests/3LocalhostTest.php with 99% similarity]
tests/6HTTPTest.php [moved from tests/4LocalhostMultiTest.php with 94% similarity]
tests/7DemofilesTest.php [moved from tests/5DemofilesTest.php with 100% similarity]
tests/8DebuggerTest.php [moved from tests/6DebuggerTest.php with 100% similarity]
tests/9ExtraFilesTest.php [moved from tests/7ExtraTest.php with 93% similarity]

index c5332ad..f94e3f4 100644 (file)
@@ -3,10 +3,10 @@
  * @author JoakimLofgren
  */
 
-use PhpXmlRpc\Helper\Charset;
-
 include_once __DIR__ . '/PolyfillTestCase.php';
 
+use PhpXmlRpc\Helper\Charset;
+
 /**
  * Test conversion between encodings
  *
@@ -14,6 +14,9 @@ include_once __DIR__ . '/PolyfillTestCase.php';
  * and run the following in cmd:
  *     chcp 28591 (latin1)
  *     chcp 65001 (utf8)
+ *
+ * @todo add tests for conversion: utf8 -> ascii
+ * @todo add tests for conversion: latin1 -> utf8
  */
 class CharsetTest extends PhpXmlRpc_PolyfillTestCase
 {
@@ -24,6 +27,7 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase
     protected $chinese = "我能吞下玻璃而不伤身体。";
     protected $latinString;
 
+    /// @todo move to usage of a dataProvider and create the latinString there
     protected function set_up()
     {
         // construct a latin string with all chars (except control ones)
@@ -36,7 +40,7 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase
         }
     }
 
-    protected function utfToLatin($data)
+    protected function utf8ToLatin1($data)
     {
         return Charset::instance()->encodeEntities(
             $data,
@@ -53,42 +57,42 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase
             'Setup latinString is not ISO-8859-1 encoded...'
         );*/
         $string = utf8_encode($this->latinString);
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals(str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $this->latinString), $encoded);
     }
 
     public function testUtf8ToLatin1EuroSymbol()
     {
         $string = 'a.b.c.å.ä.ö.€.';
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals(utf8_decode('a.b.c.å.ä.ö.&#8364;.'), $encoded);
     }
 
     public function testUtf8ToLatin1Runes()
     {
         $string = $this->runes;
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals('&#5792;&#5831;&#5819;&#5867;&#5842;&#5862;&#5798;&#5867;&#5792;&#5809;&#5801;&#5792;&#5794;&#5809;&#5867;&#5792;&#5825;&#5809;&#5802;&#5867;&#5815;&#5846;&#5819;&#5817;&#5862;&#5850;&#5811;&#5794;&#5847;', $encoded);
     }
 
     public function testUtf8ToLatin1Greek()
     {
         $string = $this->greek;
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals('&#932;&#8052; &#947;&#955;&#8182;&#963;&#963;&#945; &#956;&#959;&#8166; &#7956;&#948;&#969;&#963;&#945;&#957; &#7953;&#955;&#955;&#951;&#957;&#953;&#954;&#8052;', $encoded);
     }
 
     public function testUtf8ToLatin1Russian()
     {
         $string = $this->russian;
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals('&#1056;&#1077;&#1082;&#1072; &#1085;&#1077;&#1089;&#1083;&#1072;&#1089;&#1103;; &#1073;&#1077;&#1076;&#1085;&#1099;&#1081; &#1095;&#1105;&#1083;&#1085;', $encoded);
     }
 
     public function testUtf8ToLatin1Chinese()
     {
         $string = $this->chinese;
-        $encoded = $this->utfToLatin($string);
+        $encoded = $this->utf8ToLatin1($string);
         $this->assertEquals('&#25105;&#33021;&#21534;&#19979;&#29627;&#29827;&#32780;&#19981;&#20260;&#36523;&#20307;&#12290;', $encoded);
     }
 }
diff --git a/tests/1ValueTest.php b/tests/1ValueTest.php
new file mode 100644 (file)
index 0000000..c77432e
--- /dev/null
@@ -0,0 +1,173 @@
+<?php
+
+include_once __DIR__ . '/../lib/xmlrpc.inc';
+include_once __DIR__ . '/../lib/xmlrpcs.inc';
+
+include_once __DIR__ . '/parse_args.php';
+
+include_once __DIR__ . '/PolyfillTestCase.php';
+
+use PHPUnit\Runner\BaseTestRunner;
+
+/**
+ * Tests involving the Value class
+ */
+class ValueTests extends PhpXmlRpc_PolyfillTestCase
+{
+    public $args = array();
+
+    protected function set_up()
+    {
+        $this->args = argParser::getArgs();
+        if ($this->args['DEBUG'] == 1)
+            ob_start();
+    }
+
+    protected function tear_down()
+    {
+        if ($this->args['DEBUG'] != 1)
+            return;
+        $out = ob_get_clean();
+        $status = $this->getStatus();
+        if ($status == BaseTestRunner::STATUS_ERROR
+            || $status == BaseTestRunner::STATUS_FAILURE) {
+            echo $out;
+        }
+    }
+
+    public function testMinusOneString()
+    {
+        $v = new xmlrpcval('-1');
+        $u = new xmlrpcval('-1', 'string');
+        $t = new xmlrpcval(-1, 'string');
+        $this->assertEquals($v->scalarval(), $u->scalarval());
+        $this->assertEquals($v->scalarval(), $t->scalarval());
+    }
+
+    /**
+     * This looks funny, and we might call it a bug. But we strive for 100 backwards compat...
+     */
+    public function testMinusOneInt()
+    {
+        $u = new xmlrpcval();
+        $v = new xmlrpcval(-1);
+        $this->assertEquals($u->scalarval(), $v->scalarval());
+    }
+
+    public function testAddScalarToStruct()
+    {
+        $v = new xmlrpcval(array('a' => 'b'), 'struct');
+        // use @ operator in case error_log gets on screen
+        $r = @$v->addscalar('c');
+        $this->assertEquals(0, $r);
+    }
+
+    public function testAddStructToStruct()
+    {
+        $v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct');
+        $r = $v->addstruct(array('b' => new xmlrpcval('c')));
+        $this->assertEquals(2, $v->structsize());
+        $this->assertEquals(1, $r);
+        $r = $v->addstruct(array('b' => new xmlrpcval('b')));
+        $this->assertEquals(2, $v->structsize());
+    }
+
+    public function testAddArrayToArray()
+    {
+        $v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array');
+        $r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c')));
+        $this->assertEquals(4, $v->arraysize());
+        $this->assertEquals(1, $r);
+    }
+
+    public function testUTF8IntString()
+    {
+        $v = new xmlrpcval(100, 'int');
+        $s = $v->serialize('UTF-8');
+        $this->assertequals("<value><int>100</int></value>\n", $s);
+    }
+
+    public function testStringInt()
+    {
+        $v = new xmlrpcval('hello world', 'int');
+        $s = $v->serialize();
+        $this->assertequals("<value><int>0</int></value>\n", $s);
+    }
+
+    public function testStructMemExists()
+    {
+        $v = new xmlrpcval(array('hello' => new xmlrpcval('world')), 'struct');
+        $b = $v->structmemexists('hello');
+        $this->assertequals(true, $b);
+        $b = $v->structmemexists('world');
+        $this->assertequals(false, $b);
+    }
+
+    public function testLocale()
+    {
+        $locale = setlocale(LC_NUMERIC, 0);
+        /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
+        if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
+            $v = new xmlrpcval(1.1, 'double');
+            if (strpos($v->scalarval(), ',') == 1) {
+                $r = $v->serialize();
+                $this->assertequals(false, strpos($r, ','));
+                setlocale(LC_NUMERIC, $locale);
+            } else {
+                setlocale(LC_NUMERIC, $locale);
+                $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
+            }
+        } else {
+            $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
+        }
+    }
+
+    public function testArrayAccess()
+    {
+        $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
+        $this->assertequals(1, count($v1));
+        $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
+
+        foreach($v1 as $key => $val)
+        {
+            $this->assertArrayHasKey($key, $out);
+            $expected = $out[$key];
+            if (gettype($expected) == 'array') {
+                $this->assertequals('array', gettype($val));
+            } else {
+                $this->assertequals($expected, $val);
+            }
+        }
+
+        $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
+        $this->assertequals(2, count($v2));
+        $out = array(array('key' => 0, 'value'  => 'object'), array('key' => 1, 'value'  => 'object'));
+        $i = 0;
+        foreach($v2 as $key => $val)
+        {
+            $expected = $out[$i];
+            $this->assertequals($expected['key'], $key);
+            $this->assertequals($expected['value'], gettype($val));
+            $i++;
+        }
+    }
+
+    /// @todo do not use \PhpXmlRpc\Encoder for this test
+    function testBigXML()
+    {
+        // nb: make sure that  the serialized xml corresponding to this is > 10MB in size
+        $data = array();
+        for ($i = 0; $i < 500000; $i++ ) {
+            $data[] = 'hello world';
+        }
+
+        $encoder = new \PhpXmlRpc\Encoder();
+        $val = $encoder->encode($data);
+        $req = new \PhpXmlRpc\Request('test', array($val));
+        $xml = $req->serialize();
+        $parser = new \PhpXmlRpc\Helper\XMLParser();
+        $parser->parse($xml);
+
+        $this->assertequals(0, $parser->_xh['isf']);
+    }
+}
similarity index 71%
rename from tests/1ParsingBugsTest.php
rename to tests/2MessageTest.php
index 3fa7b8e..bb7461a 100644 (file)
@@ -1,7 +1,5 @@
 <?php
-/**
- * NB: do not let your IDE fool you. The correct encoding for this file is NOT UTF8.
- */
+
 include_once __DIR__ . '/../lib/xmlrpc.inc';
 include_once __DIR__ . '/../lib/xmlrpcs.inc';
 
@@ -12,9 +10,11 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests involving parsing of xml and handling of xmlrpc values
+ * Tests involving the Request and Response classes.
+ * @todo some tests are here only because we use a Response to trigger parsing of xml for a single Value, but they
+ *       logically belong elsewhere...
  */
-class ParsingBugsTests extends PhpXmlRpc_PolyfillTestCase
+class MessageTests extends PhpXmlRpc_PolyfillTestCase
 {
     public $args = array();
 
@@ -44,65 +44,6 @@ class ParsingBugsTests extends PhpXmlRpc_PolyfillTestCase
         return $msg;
     }
 
-    public function testMinusOneString()
-    {
-        $v = new xmlrpcval('-1');
-        $u = new xmlrpcval('-1', 'string');
-        $t = new xmlrpcval(-1, 'string');
-        $this->assertEquals($v->scalarval(), $u->scalarval());
-        $this->assertEquals($v->scalarval(), $t->scalarval());
-    }
-
-    /**
-     * This looks funny, and we might call it a bug. But we strive for 100 backwards compat...
-     */
-    public function testMinusOneInt()
-    {
-        $u = new xmlrpcval();
-        $v = new xmlrpcval(-1);
-        $this->assertEquals($u->scalarval(), $v->scalarval());
-    }
-
-    public function testUnicodeInMemberName()
-    {
-        $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
-        $v = array($str => new xmlrpcval(1));
-        $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
-        $r = $r->serialize();
-        $m = $this->newMsg('dummy');
-        $r = $m->parseResponse($r);
-        $v = $r->value();
-        $this->assertEquals(true, $v->structmemexists($str));
-    }
-
-    public function testUnicodeInErrorString()
-    {
-        $response = utf8_encode(
-            '<?xml version="1.0"?>
-<!-- $Id -->
-<!-- found by G. Giunta, covers what happens when lib receives UTF8 chars in response text and comments -->
-<!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
-<methodResponse>
-<fault>
-<value>
-<struct>
-<member>
-<name>faultCode</name>
-<value><int>888</int></value>
-</member>
-<member>
-<name>faultString</name>
-<value><string>' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232;</string></value>
-</member>
-</struct>
-</value>
-</fault>
-</methodResponse>');
-        $m = $this->newMsg('dummy');
-        $r = $m->parseResponse($response);
-        $v = $r->faultString();
-        $this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v);
-    }
 
     public function testValidNumbers()
     {
@@ -190,43 +131,45 @@ class ParsingBugsTests extends PhpXmlRpc_PolyfillTestCase
         $this->assertEquals(1, $s->scalarval());
     }
 
-    public function testAddScalarToStruct()
-    {
-        $v = new xmlrpcval(array('a' => 'b'), 'struct');
-        // use @ operator in case error_log gets on screen
-        $r = @$v->addscalar('c');
-        $this->assertEquals(0, $r);
-    }
-
-    public function testAddStructToStruct()
-    {
-        $v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct');
-        $r = $v->addstruct(array('b' => new xmlrpcval('c')));
-        $this->assertEquals(2, $v->structsize());
-        $this->assertEquals(1, $r);
-        $r = $v->addstruct(array('b' => new xmlrpcval('b')));
-        $this->assertEquals(2, $v->structsize());
-    }
-
-    public function testAddArrayToArray()
-    {
-        $v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array');
-        $r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c')));
-        $this->assertEquals(4, $v->arraysize());
-        $this->assertEquals(1, $r);
-    }
-
-    public function testEncodeArray()
+    public function testUnicodeInMemberName()
     {
-        $r = range(1, 100);
-        $v = php_xmlrpc_encode($r);
-        $this->assertEquals('array', $v->kindof());
+        $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
+        $v = array($str => new xmlrpcval(1));
+        $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
+        $r = $r->serialize();
+        $m = $this->newMsg('dummy');
+        $r = $m->parseResponse($r);
+        $v = $r->value();
+        $this->assertEquals(true, $v->structmemexists($str));
     }
 
-    public function testEncodeRecursive()
+    public function testUnicodeInErrorString()
     {
-        $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
-        $this->assertEquals('scalar', $v->kindof());
+        $response = utf8_encode(
+            '<?xml version="1.0"?>
+<!-- $Id -->
+<!-- found by G. Giunta, covers what happens when lib receives UTF8 chars in response text and comments -->
+<!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
+<methodResponse>
+<fault>
+<value>
+<struct>
+<member>
+<name>faultCode</name>
+<value><int>888</int></value>
+</member>
+<member>
+<name>faultString</name>
+<value><string>' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232;</string></value>
+</member>
+</struct>
+</value>
+</fault>
+</methodResponse>');
+        $m = $this->newMsg('dummy');
+        $r = $m->parseResponse($response);
+        $v = $r->faultString();
+        $this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v);
     }
 
     public function testBrokenRequests()
@@ -428,7 +371,7 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
     {
         $s = $this->newMsg('dummy');
         $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
-<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
+<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 3 newlines follow
 
 
 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
@@ -436,14 +379,14 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $r = $s->parseResponse($f, true, 'phpvals');
         $v = $r->value();
         $s = $v['content'];
-        $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s);
+        $this->assertEquals("hello world. 3 newlines follow\n\n\nand there they were.", $s);
     }
 
     public function testNoDecodeResponse()
     {
         $s = $this->newMsg('dummy');
         $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
-<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
+<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 3 newlines follow
 
 
 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>';
@@ -452,25 +395,6 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $this->assertEquals($f, $v);
     }
 
-    public function testAutoCoDec()
-    {
-        $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
-        $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
-        $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
-        //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
-        $v1 = php_xmlrpc_encode($data, array('auto_dates'));
-        $v2 = php_xmlrpc_decode_xml($v1->serialize());
-        $this->assertEquals($v1, $v2);
-        $r1 = new PhpXmlRpc\Response($v1);
-        $r2 = php_xmlrpc_decode_xml($r1->serialize());
-        $r2->serialize(); // needed to set internal member payload
-        $this->assertEquals($r1, $r2);
-        $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
-        $m2 = php_xmlrpc_decode_xml($m1->serialize());
-        $m2->serialize(); // needed to set internal member payload
-        $this->assertEquals($m1, $m2);
-    }
-
     public function testUTF8Request()
     {
         $sendstring = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
@@ -504,6 +428,7 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $v = $v['content'];
         $this->assertEquals($string, $v);
 
+        /// @todo move to EncoderTest
         $r = php_xmlrpc_decode_xml($f);
         $v = $r->value();
         $v = $v->structmem('content')->scalarval();
@@ -531,35 +456,14 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $v = $v['content'];
         $this->assertEquals($string, $v);
 
+        /// @todo move to EncoderTest
         $r = php_xmlrpc_decode_xml($f);
         $v = $r->value();
         $v = $v->structmem('content')->scalarval();
         $this->assertEquals($string, $v);
     }
 
-    public function testUTF8IntString()
-    {
-        $v = new xmlrpcval(100, 'int');
-        $s = $v->serialize('UTF-8');
-        $this->assertequals("<value><int>100</int></value>\n", $s);
-    }
-
-    public function testStringInt()
-    {
-        $v = new xmlrpcval('hello world', 'int');
-        $s = $v->serialize();
-        $this->assertequals("<value><int>0</int></value>\n", $s);
-    }
-
-    public function testStructMemExists()
-    {
-        $v = php_xmlrpc_encode(array('hello' => 'world'));
-        $b = $v->structmemexists('hello');
-        $this->assertequals(true, $b);
-        $b = $v->structmemexists('world');
-        $this->assertequals(false, $b);
-    }
-
+    /// @todo can we change this test to purely using the Value class ?
     public function testNilvalue()
     {
         // default case: we do not accept nil values received
@@ -593,71 +497,4 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $r = $m->parseresponse($s);
         $this->assertequals(2, $r->faultCode());
     }
-
-    public function testLocale()
-    {
-        $locale = setlocale(LC_NUMERIC, 0);
-        /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
-        if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
-            $v = new xmlrpcval(1.1, 'double');
-            if (strpos($v->scalarval(), ',') == 1) {
-                $r = $v->serialize();
-                $this->assertequals(false, strpos($r, ','));
-                setlocale(LC_NUMERIC, $locale);
-            } else {
-                setlocale(LC_NUMERIC, $locale);
-                $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
-            }
-        } else {
-            $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
-        }
-    }
-
-    public function testArrayAccess()
-    {
-        $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
-        $this->assertequals(1, count($v1));
-        $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
-
-        foreach($v1 as $key => $val)
-        {
-            $this->assertArrayHasKey($key, $out);
-            $expected = $out[$key];
-            if (gettype($expected) == 'array') {
-                $this->assertequals('array', gettype($val));
-            } else {
-                $this->assertequals($expected, $val);
-            }
-        }
-
-        $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
-        $this->assertequals(2, count($v2));
-        $out = array(array('key' => 0, 'value'  => 'object'), array('key' => 1, 'value'  => 'object'));
-        $i = 0;
-        foreach($v2 as $key => $val)
-        {
-            $expected = $out[$i];
-            $this->assertequals($expected['key'], $key);
-            $this->assertequals($expected['value'], gettype($val));
-            $i++;
-        }
-    }
-
-    function testBigXML()
-    {
-        // nb: make sure that  the serialized xml corresponding to this is > 10MB in size
-        $data = array();
-        for ($i = 0; $i < 500000; $i++ ) {
-            $data[] = 'hello world';
-        }
-
-        $encoder = new \PhpXmlRpc\Encoder();
-        $val = $encoder->encode($data);
-        $req = new \PhpXmlRpc\Request('test', array($val));
-        $xml = $req->serialize();
-        $parser = new \PhpXmlRpc\Helper\XMLParser();
-        $parser->parse($xml);
-
-        $this->assertequals(0, $parser->_xh['isf']);
-    }
 }
diff --git a/tests/3EncoderTest.php b/tests/3EncoderTest.php
new file mode 100644 (file)
index 0000000..7621c6d
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+
+include_once __DIR__ . '/../lib/xmlrpc.inc';
+include_once __DIR__ . '/../lib/xmlrpcs.inc';
+
+include_once __DIR__ . '/parse_args.php';
+
+include_once __DIR__ . '/PolyfillTestCase.php';
+
+use PHPUnit\Runner\BaseTestRunner;
+
+/**
+ * Tests involving automatic encoding/decoding of php values into xmlrpc values
+ * @todo add tests for encoding options: 'encode_php_objs', 'auto_dates', 'null_extension' and 'extension_api'
+ * @todo add tests for php_xmlrpc_decode options
+ */
+class EncoderTests extends PhpXmlRpc_PolyfillTestCase
+{
+    public $args = array();
+
+    protected function set_up()
+    {
+        $this->args = argParser::getArgs();
+        if ($this->args['DEBUG'] == 1)
+            ob_start();
+    }
+
+    protected function tear_down()
+    {
+        if ($this->args['DEBUG'] != 1)
+            return;
+        $out = ob_get_clean();
+        $status = $this->getStatus();
+        if ($status == BaseTestRunner::STATUS_ERROR
+            || $status == BaseTestRunner::STATUS_FAILURE) {
+            echo $out;
+        }
+    }
+
+    public function testEncodeArray()
+    {
+        $v = php_xmlrpc_encode(array());
+        $this->assertEquals('array', $v->kindof());
+
+        $r = range(1, 10);
+        $v = php_xmlrpc_encode($r);
+        $this->assertEquals('array', $v->kindof());
+
+        $r['.'] = '...';
+        $v = php_xmlrpc_encode($r);
+        $this->assertEquals('struct', $v->kindof());
+    }
+
+    public function testEncodeDate()
+    {
+        $r = new DateTime();
+        $v = php_xmlrpc_encode($r);
+        $this->assertEquals('dateTime.iso8601', $v->kindof());
+    }
+
+    public function testEncodeRecursive()
+    {
+        $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
+        $this->assertEquals('scalar', $v->kindof());
+    }
+
+    public function testAutoCoDec()
+    {
+        $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
+        $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
+        $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
+        //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
+        $v1 = php_xmlrpc_encode($data, array('auto_dates'));
+        $v2 = php_xmlrpc_decode_xml($v1->serialize());
+        $this->assertEquals($v1, $v2);
+        $r1 = new PhpXmlRpc\Response($v1);
+        $r2 = php_xmlrpc_decode_xml($r1->serialize());
+        $r2->serialize(); // needed to set internal member payload
+        $this->assertEquals($r1, $r2);
+        $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
+        $m2 = php_xmlrpc_decode_xml($m1->serialize());
+        $m2->serialize(); // needed to set internal member payload
+        $this->assertEquals($m1, $m2);
+    }
+}
similarity index 95%
rename from tests/2InvalidHostTest.php
rename to tests/4ClientTest.php
index c7419ec..159cb0c 100644 (file)
@@ -9,9 +9,10 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests involving requests sent to non-existing servers
+ * Tests involving the Client class.
+ * So far: only tests requests sent to non-existing servers
  */
-class InvalidHostTest extends PhpXmlRpc_PolyfillTestCase
+class ClientTest extends PhpXmlRpc_PolyfillTestCase
 {
     /** @var xmlrpc_client $client */
     public $client = null;
similarity index 99%
rename from tests/3LocalhostTest.php
rename to tests/5ServerTest.php
index 5f4c63a..92d8ba9 100644 (file)
@@ -13,9 +13,10 @@ use PHPUnit\Runner\BaseTestRunner;
 
 /**
  * Tests which involve interaction between the client and the server.
- * They are run against the server found in demo/server.php
+ * They are run against the server found in demo/server.php.
+ * Includes testing of (some of) the Wrapper class
  */
-class LocalhostTest extends PhpXmlRpc_PolyfillTestCase
+class ServerTest extends PhpXmlRpc_PolyfillTestCase
 {
     /** @var xmlrpc_client $client */
     protected $client = null;
similarity index 94%
rename from tests/4LocalhostMultiTest.php
rename to tests/6HTTPTest.php
index 619e3ae..74b8a01 100644 (file)
@@ -5,13 +5,13 @@ include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
 
 include_once __DIR__ . '/parse_args.php';
 
-include_once __DIR__ . '/3LocalhostTest.php';
+include_once __DIR__ . '/5ServerTest.php';
 
 /**
  * Tests which stress http features of the library.
  * Each of these tests iterates over (almost) all of the 'localhost' tests
  */
-class LocalhostMultiTest extends LocalhostTest
+class HTTPTest extends ServerTest
 {
     /**
      * Returns all test methods from the base class, except the ones which failed already
@@ -27,9 +27,9 @@ class LocalhostMultiTest extends LocalhostTest
         );
 
         $methods = array();
-        foreach(get_class_methods('LocalhostTest') as $method)
+        foreach(get_class_methods('ServerTest') as $method)
         {
-            if(strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
+            if (strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
             {
                 if (!isset(self::$failed_tests[$method])) {
                     $methods[$method] = array($method);
@@ -46,7 +46,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testDeflate($method)
     {
-        if(!function_exists('gzdeflate'))
+        if (!function_exists('gzdeflate'))
         {
             $this->markTestSkipped('Zlib missing: cannot test deflate functionality');
             return;
@@ -64,7 +64,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testGzip($method)
     {
-        if(!function_exists('gzdeflate'))
+        if (!function_exists('gzdeflate'))
         {
             $this->markTestSkipped('Zlib missing: cannot test gzip functionality');
             return;
@@ -78,7 +78,7 @@ class LocalhostMultiTest extends LocalhostTest
 
     public function testKeepAlives()
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1');
             return;
@@ -118,7 +118,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttp11($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1');
             return;
@@ -137,7 +137,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttp10Curl($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1');
             return;
@@ -157,7 +157,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttp11Gzip($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1');
             return;
@@ -177,7 +177,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttp11Deflate($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1');
             return;
@@ -197,7 +197,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttp11Proxy($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
             return;
@@ -222,7 +222,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttps($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test https functionality');
             return;
@@ -274,7 +274,7 @@ class LocalhostMultiTest extends LocalhostTest
      */
     public function testHttpsProxy($method)
     {
-        if(!function_exists('curl_init'))
+        if (!function_exists('curl_init'))
         {
             $this->markTestSkipped('CURL missing: cannot test https w. proxy');
             return;
similarity index 93%
rename from tests/7ExtraTest.php
rename to tests/9ExtraFilesTest.php
index 48acf6b..64b2d8a 100644 (file)
@@ -6,7 +6,7 @@ include_once __DIR__ . '/LocalFileTestCase.php';
  * Tests for php files in the 'extras' directory
  *
  */
-class ExtraTest extends PhpXmlRpc_LocalFileTestCase
+class ExtraFilesTest extends PhpXmlRpc_LocalFileTestCase
 {
     public function set_up()
     {