Improve the way test suite reports error messages at DEBUG=1
authorgggeek <giunta.gaetano@gmail.com>
Tue, 14 Apr 2015 22:29:15 +0000 (23:29 +0100)
committergggeek <giunta.gaetano@gmail.com>
Tue, 14 Apr 2015 22:29:15 +0000 (23:29 +0100)
NEWS
src/Client.php
tests/1ParsingBugsTest.php
tests/2InvalidHostTest.php
tests/3LocalhostTest.php

diff --git a/NEWS b/NEWS
index b2c5fb3..6d86918 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,7 +49,10 @@ PLEASE READ CAREFULLY THE NOTES BELOW to insure a smooth upgrade.
 * improved: echo all debug messages even when there are characters in them which php deems in a wrong encoding
   (this is visible e.g. in the debugger)
 
-* improved: at debug level 1, the rebuilt php objects are not dumped to screen (server-side already did that)
+* changed: debug info handling
+    - at debug level 1, the rebuilt php objects are not dumped to screen (server-side already did that)
+    - at debug level 1, curl communication info are not dumped to screen
+    - at debug level 1, the tests echo payloads of failures; at debug level 2 all payloads
 
 
 XML-RPC for PHP version 3.0.0 - 2014/6/15
index 4c784d5..214d970 100644 (file)
@@ -722,10 +722,10 @@ class Client
         }
 
         // results into variable
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
-        if ($this->debug) {
-            curl_setopt($curl, CURLOPT_VERBOSE, 1);
+        if ($this->debug > 1) {
+            curl_setopt($curl, CURLOPT_VERBOSE, true);
             /// @todo allow callers to redirect curlopt_stderr to some stream which can be buffered
         }
         curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
index 4bbccba..28bb9d5 100644 (file)
@@ -9,17 +9,29 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
 {
     public $args = array();
 
-    public function setUp()
+    protected function setUp()
     {
         $this->args = argParser::getArgs();
+        if ($this->args['DEBUG'] == 1)
+            ob_start();
+    }
+
+    protected function tearDown()
+    {
+        if ($this->args['DEBUG'] != 1)
+            return;
+        $out = ob_get_clean();
+        $status = $this->getStatus();
+        if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
+            || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
+            echo $out;
+        }
     }
 
     protected function newMsg($methodName, $params = array())
     {
         $msg = new xmlrpcmsg($methodName, $params);
-        if ($this->args['DEBUG']) {
-            $msg->setDebug($this->args['DEBUG']);
-        }
+        $msg->setDebug($this->args['DEBUG']);
         return $msg;
     }
 
index 685bd59..0168c91 100644 (file)
@@ -15,8 +15,21 @@ class InvalidHostTest extends PHPUnit_Framework_TestCase
         $this->args = argParser::getArgs();
 
         $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80);
-        if ($this->args['DEBUG']) {
-            $this->client->setDebug($this->args['DEBUG']);
+        $this->client->setDebug($this->args['DEBUG']);
+
+        if ($this->args['DEBUG'] == 1)
+            ob_start();
+    }
+
+    protected function tearDown()
+    {
+        if ($this->args['DEBUG'] != 1)
+            return;
+        $out = ob_get_clean();
+        $status = $this->getStatus();
+        if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
+            || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
+            echo $out;
         }
     }
 
index a0e9b2a..ea7c5bf 100644 (file)
@@ -85,13 +85,27 @@ class LocalhostTest extends PHPUnit_Framework_TestCase
         } else {
             $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']);
         }
-        if ($this->args['DEBUG']) {
-            $this->client->setDebug($this->args['DEBUG']);
-        }
+
+        $this->client->setDebug($this->args['DEBUG']);
         $this->client->request_compression = $this->request_compression;
         $this->client->accepted_compression = $this->accepted_compression;
 
         $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+
+        if ($this->args['DEBUG'] == 1)
+            ob_start();
+    }
+
+    protected function tearDown()
+    {
+        if ($this->args['DEBUG'] != 1)
+            return;
+        $out = ob_get_clean();
+        $status = $this->getStatus();
+        if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
+            || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
+            echo $out;
+        }
     }
 
     protected function send($msg, $errrorcode = 0, $return_response = false)