moar tests!
authorgggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 16:15:43 +0000 (16:15 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 16:15:43 +0000 (16:15 +0000)
tests/03ParsingTest.php
tests/04LoggerTest.php [new file with mode: 0644]
tests/06EncoderTest.php
tests/07ClientTest.php
tests/08ServerTest.php
tests/12ExtraFilesTest.php
tests/WebTestCase.php

index 2510ab6..0237451 100644 (file)
@@ -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 (file)
index 0000000..2653e54
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+include_once __DIR__ . '/PolyfillTestCase.php';
+
+use PhpXmlRpc\Helper\Charset;
+use PhpXmlRpc\Helper\Http;
+use PhpXmlRpc\Helper\XMLParser;
+
+class LoggerTest extends PhpXmlRpc_PolyfillTestCase
+{
+    protected $debugBuffer = '';
+    protected $errorBuffer = '';
+
+    protected function set_up()
+    {
+        $this->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('<?xml version="1.0" ?><methodResponse><params><param><value><boolean> 1 </boolean></value></param></params></methodResponse>');
+        $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;
+    }
+}
index 507c40d..59ba798 100644 (file)
@@ -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();
     }
index a2942b4..a43b827 100644 (file)
@@ -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();
index 44f6dee..72c8069 100644 (file)
@@ -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();
index 456d7f2..034d3ce 100644 (file)
@@ -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']);
     }
 
index 190b971..bf721b1 100644 (file)
@@ -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;
     }
 }