From dc6f852fe9ca7a2e3f5c3b98a2179f60d335b5b5 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 23 Jan 2023 16:15:43 +0000 Subject: [PATCH] moar tests! --- tests/03ParsingTest.php | 5 +-- tests/04LoggerTest.php | 71 ++++++++++++++++++++++++++++++++++++++ tests/06EncoderTest.php | 1 + tests/07ClientTest.php | 5 +-- tests/08ServerTest.php | 5 +-- tests/12ExtraFilesTest.php | 2 +- tests/WebTestCase.php | 5 +-- 7 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 tests/04LoggerTest.php diff --git a/tests/03ParsingTest.php b/tests/03ParsingTest.php index 2510ab68..02374515 100644 --- a/tests/03ParsingTest.php +++ b/tests/03ParsingTest.php @@ -21,13 +21,14 @@ class ParsingTests extends PhpXmlRpc_PolyfillTestCase protected function set_up() { $this->args = argParser::getArgs(); - if ($this->args['DEBUG'] == 1) + // hide parsing errors unless in debug mode + if ($this->args['DEBUG'] < 1) ob_start(); } protected function tear_down() { - if ($this->args['DEBUG'] != 1) + if ($this->args['DEBUG'] >= 1) return; $out = ob_get_clean(); $status = $this->getStatus(); diff --git a/tests/04LoggerTest.php b/tests/04LoggerTest.php new file mode 100644 index 00000000..2653e54d --- /dev/null +++ b/tests/04LoggerTest.php @@ -0,0 +1,71 @@ +debugBuffer = ''; + $this->errorBuffer = ''; + } + + public function testCharsetAltLogger() + { + $ch = Charset::instance(); + $l = $ch->getLogger(); + Charset::setLogger($this); + + // silence the mbstring warning + $ch->encodeEntities('hello world', 'UTF-8', 'NOT-A-CHARSET'); + $this->assertStringContainsString("via mbstring: failed", $this->errorBuffer); + + Charset::setLogger($l); + } + + public function testHttpAltLogger() + { + $l = Http::getLogger(); + Http::setLogger($this); + + $h = new Http(); + $s = "HTTP/1.0 200 OK\r\n" . + "Content-Type: unknown\r\n" . + "\r\n" . + "body"; + $h->parseResponseHeaders($s, false, 1); + $this->assertStringContainsString("HEADER: content-type: unknown", $this->debugBuffer); + Http::setLogger($l); + } + + public function testXPAltLogger() + { + $xp = new XMLParser(); + $l = $xp->getLogger(); + XMLParser::setLogger($this); + + $xp->parse(' 1 '); + $this->assertStringContainsString("invalid data received in BOOLEAN value", $this->errorBuffer); + + XMLParser::setLogger($l); + } + + // logger API + + public function debugMessage($message, $encoding = null) + { + $this->debugBuffer .= $message; + } + + public function errorLog($message) + { + $this->errorBuffer .= $message; + } +} diff --git a/tests/06EncoderTest.php b/tests/06EncoderTest.php index 507c40d8..59ba798e 100644 --- a/tests/06EncoderTest.php +++ b/tests/06EncoderTest.php @@ -22,6 +22,7 @@ class EncoderTests extends PhpXmlRpc_PolyfillTestCase protected function set_up() { $this->args = argParser::getArgs(); + // hide parsing errors unless in debug mode if ($this->args['DEBUG'] == 1) ob_start(); } diff --git a/tests/07ClientTest.php b/tests/07ClientTest.php index a2942b4c..a43b827e 100644 --- a/tests/07ClientTest.php +++ b/tests/07ClientTest.php @@ -25,13 +25,14 @@ class ClientTest extends PhpXmlRpc_PolyfillTestCase $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80); $this->client->setDebug($this->args['DEBUG']); - if ($this->args['DEBUG'] == 1) + // in debug mode, the client will be very verbose. Avoid showing its output unless there are errors + if ($this->args['DEBUG'] >= 1) ob_start(); } protected function tear_down() { - if ($this->args['DEBUG'] != 1) + if ($this->args['DEBUG'] < 1) return; $out = ob_get_clean(); $status = $this->getStatus(); diff --git a/tests/08ServerTest.php b/tests/08ServerTest.php index 44f6deee..72c80690 100644 --- a/tests/08ServerTest.php +++ b/tests/08ServerTest.php @@ -108,13 +108,14 @@ class ServerTest extends PhpXmlRpc_PolyfillTestCase $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']); - if ($this->args['DEBUG'] == 1) + // in debug mode, the client will be very verbose. Avoid showing its output unless there are errors + if ($this->args['DEBUG'] >= 1) ob_start(); } protected function tear_down() { - if ($this->args['DEBUG'] != 1) + if ($this->args['DEBUG'] < 1) return; $out = ob_get_clean(); $status = $this->getStatus(); diff --git a/tests/12ExtraFilesTest.php b/tests/12ExtraFilesTest.php index 456d7f24..034d3cea 100644 --- a/tests/12ExtraFilesTest.php +++ b/tests/12ExtraFilesTest.php @@ -12,7 +12,7 @@ class ExtraFilesTest extends PhpXmlRpc_WebTestCase $this->args = argParser::getArgs(); // assumes HTTPURI to be in the form /tests/index.php?etc... - $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']); + $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']); $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']); } diff --git a/tests/WebTestCase.php b/tests/WebTestCase.php index 190b971b..bf721b19 100644 --- a/tests/WebTestCase.php +++ b/tests/WebTestCase.php @@ -100,8 +100,9 @@ abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_PolyfillTestCase if ($this->collectCodeCoverageInformation) { $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId); } - $client->setAcceptedCompression(false); - $client->setDebug($this->args['DEBUG']); + // let's just assume that the client works fine for these tests, and avoid polluting output + //$client->setAcceptedCompression(false); + //$client->setDebug($this->args['DEBUG']); return $client; } } -- 2.47.0