From 9337670bd021202018213a156c0083dd72902571 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 14 Apr 2015 23:29:15 +0100 Subject: [PATCH] Improve the way test suite reports error messages at DEBUG=1 --- NEWS | 5 ++++- src/Client.php | 6 +++--- tests/1ParsingBugsTest.php | 20 ++++++++++++++++---- tests/2InvalidHostTest.php | 17 +++++++++++++++-- tests/3LocalhostTest.php | 20 +++++++++++++++++--- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index b2c5fb3..6d86918 100644 --- 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 diff --git a/src/Client.php b/src/Client.php index 4c784d5..214d970 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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); diff --git a/tests/1ParsingBugsTest.php b/tests/1ParsingBugsTest.php index 4bbccba..28bb9d5 100644 --- a/tests/1ParsingBugsTest.php +++ b/tests/1ParsingBugsTest.php @@ -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; } diff --git a/tests/2InvalidHostTest.php b/tests/2InvalidHostTest.php index 685bd59..0168c91 100644 --- a/tests/2InvalidHostTest.php +++ b/tests/2InvalidHostTest.php @@ -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; } } diff --git a/tests/3LocalhostTest.php b/tests/3LocalhostTest.php index a0e9b2a..ea7c5bf 100644 --- a/tests/3LocalhostTest.php +++ b/tests/3LocalhostTest.php @@ -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) -- 2.43.0