Add the multiTest suite; minor test fixes
authorgggeek <giunta.gaetano@gmail.com>
Fri, 20 Mar 2015 01:54:52 +0000 (01:54 +0000)
committergggeek <giunta.gaetano@gmail.com>
Fri, 20 Mar 2015 01:54:52 +0000 (01:54 +0000)
tests/InvalidHostTest.php
tests/LocalhostMultiTest.php [new file with mode: 0644]
tests/LocalhostTest.php
tests/parse_args.php

index 1ac111f..685bd59 100644 (file)
@@ -6,6 +6,7 @@ include_once __DIR__ . '/parse_args.php';
 
 class InvalidHostTest extends PHPUnit_Framework_TestCase
 {
+    /** @var xmlrpc_client $client */
     public $client = null;
     public $args = array();
 
diff --git a/tests/LocalhostMultiTest.php b/tests/LocalhostMultiTest.php
new file mode 100644 (file)
index 0000000..e855f21
--- /dev/null
@@ -0,0 +1,206 @@
+<?php
+
+include_once __DIR__ . '/../lib/xmlrpc.inc';
+include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
+
+include_once __DIR__ . '/parse_args.php';
+
+include_once __DIR__ . '/LocalHostTest.php';
+
+class LocalhostMultiTest extends LocalhostTest
+{
+    /**
+     * @todo reintroduce skipping of tests which failed when executed individually if test runs happen as separate processes
+     * @todo reintroduce skipping of tests within the loop
+     */
+    function _runtests()
+    {
+        foreach(get_class_methods('LocalhostTest') as $method)
+        {
+            if(strpos($method, 'test') === 0 && $method != 'testHttps' && $method != 'testCatchExceptions')
+            {
+                if (!isset(self::$failed_tests[$method]))
+                    $this->$method();
+            }
+            /*if ($this->_failed)
+            {
+                break;
+            }*/
+        }
+    }
+
+    function testDeflate()
+    {
+        if(!function_exists('gzdeflate'))
+        {
+            $this->fail('Zlib missing: cannot test deflate functionality');
+            return;
+        }
+        $this->client->accepted_compression = array('deflate');
+        $this->client->request_compression = 'deflate';
+        $this->_runtests();
+    }
+
+    function testGzip()
+    {
+        if(!function_exists('gzdeflate'))
+        {
+            $this->fail('Zlib missing: cannot test gzip functionality');
+            return;
+        }
+        $this->client->accepted_compression = array('gzip');
+        $this->client->request_compression = 'gzip';
+        $this->_runtests();
+    }
+
+    function testKeepAlives()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test http 1.1');
+            return;
+        }
+        $this->method = 'http11';
+        $this->client->keepalive = true;
+        $this->_runtests();
+    }
+
+    function testProxy()
+    {
+        if ($this->args['PROXYSERVER'])
+        {
+            $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
+            $this->_runtests();
+        }
+        else
+            $this->fail('PROXY definition missing: cannot test proxy');
+    }
+
+    function testHttp11()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test http 1.1');
+            return;
+        }
+        $this->method = 'http11'; // not an error the double assignment!
+        $this->client->method = 'http11';
+        //$this->client->verifyhost = 0;
+        //$this->client->verifypeer = 0;
+        $this->client->keepalive = false;
+        $this->_runtests();
+    }
+
+    function testHttp11Gzip()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test http 1.1');
+            return;
+        }
+        $this->method = 'http11'; // not an error the double assignment!
+        $this->client->method = 'http11';
+        $this->client->keepalive = false;
+        $this->client->accepted_compression = array('gzip');
+        $this->client->request_compression = 'gzip';
+        $this->_runtests();
+    }
+
+    function testHttp11Deflate()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test http 1.1');
+            return;
+        }
+        $this->method = 'http11'; // not an error the double assignment!
+        $this->client->method = 'http11';
+        $this->client->keepalive = false;
+        $this->client->accepted_compression = array('deflate');
+        $this->client->request_compression = 'deflate';
+        $this->_runtests();
+    }
+
+    function testHttp11Proxy()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test http 1.1 w. proxy');
+            return;
+        }
+        else if ($this->args['PROXYSERVER'] == '')
+        {
+            $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
+            return;
+        }
+        $this->method = 'http11'; // not an error the double assignment!
+        $this->client->method = 'http11';
+        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
+        //$this->client->verifyhost = 0;
+        //$this->client->verifypeer = 0;
+        $this->client->keepalive = false;
+        $this->_runtests();
+    }
+
+    function testHttps()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test https functionality');
+            return;
+        }
+        $this->client->server = $this->args['HTTPSSERVER'];
+        $this->method = 'https';
+        $this->client->method = 'https';
+        $this->client->path = $this->args['HTTPSURI'];
+        $this->client->setSSLVerifyPeer( !$this->args['HTTPSIGNOREPEER'] );
+        $this->_runtests();
+    }
+
+    function testHttpsProxy()
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->fail('CURL missing: cannot test https functionality');
+            return;
+        }
+        else if ($this->args['PROXYSERVER'] == '')
+        {
+            $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
+            return;
+        }
+        $this->client->server = $this->args['HTTPSSERVER'];
+        $this->method = 'https';
+        $this->client->method = 'https';
+        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
+        $this->client->path = $this->args['HTTPSURI'];
+        $this->client->setSSLVerifyPeer( !$this->args['HTTPSIGNOREPEER'] );
+        $this->_runtests();
+    }
+
+    function testUTF8Responses()
+    {
+        //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
+        $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=UTF-8';
+        $this->_runtests();
+    }
+
+    function testUTF8Requests()
+    {
+        $this->client->request_charset_encoding = 'UTF-8';
+        $this->_runtests();
+    }
+
+    function testISOResponses()
+    {
+        //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
+        $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=ISO-8859-1';
+        $this->_runtests();
+    }
+
+    function testISORequests()
+    {
+        $this->client->request_charset_encoding = 'ISO-8859-1';
+        $this->_runtests();
+    }
+}
index 9082251..562dbb5 100644 (file)
@@ -7,6 +7,7 @@ include_once __DIR__ . '/parse_args.php';
 
 class LocalhostTest extends PHPUnit_Framework_TestCase
 {
+    /** @var xmlrpc_client $client */
     public $client = null;
     public $method = 'http';
     public $timeout = 10;
@@ -14,6 +15,8 @@ class LocalhostTest extends PHPUnit_Framework_TestCase
     public $accepted_compression = '';
     public $args = array();
 
+    protected static $failed_tests = array();
+
     public static function fail($message = '')
     {
         // save in global var that this particular test has failed
@@ -23,7 +26,7 @@ class LocalhostTest extends PHPUnit_Framework_TestCase
             $trace = debug_backtrace();
             for ($i = 0; $i < count($trace); $i++) {
                 if (strpos($trace[$i]['function'], 'test') === 0) {
-                    $failed_tests[$trace[$i]['function']] = true;
+                    self::$failed_tests[$trace[$i]['function']] = true;
                     break;
                 }
             }
index 744afbf..e9f2e2e 100644 (file)
@@ -67,7 +67,7 @@ class argParser
             $args['HTTPSURI'] = $HTTPSURI;
         }
         if (isset($HTTPSIGNOREPEER)) {
-            $args['HTTPSIGNOREPEER'] = bool($HTTPSIGNOREPEER);
+            $args['HTTPSIGNOREPEER'] = (bool)$HTTPSIGNOREPEER;
         }
         if (isset($PROXY)) {
             $arr = explode(':', $PROXY);