update tests for newer libcurl
authorMichael Wallner <mike@php.net>
Tue, 26 Feb 2019 15:40:44 +0000 (16:40 +0100)
committerMichael Wallner <mike@php.net>
Tue, 26 Feb 2019 17:08:55 +0000 (18:08 +0100)
tests/client008.phpt
tests/client018.phpt
tests/client021.phpt

index 3f5641fdf040dd1d8ca9e1e8a15e9cf42444bccc..c544cb5d218fbb0f076e4932a7256bc016d86fba 100644 (file)
@@ -1,9 +1,12 @@
 --TEST--
-client configuration
+client pipelining
 --SKIPIF--
 <?php
 include "skipif.inc";
 skip_client_test();
+if (version_compare(http\Client\Curl\Versions\CURL, "7.62.0", ">=")) {
+       die("skip CURL_VERSION >= 7.62 -- pipelining disabled\n");
+}
 ?>
 --FILE--
 <?php
@@ -18,7 +21,7 @@ server("pipeline.inc", function($port, $stdin) {
        $request = new http\Client\Request("GET", "http://localhost:$port");
        
        $client = new http\Client();
-       $client->configure(array("pipelining" => true, "use_eventloop" => true));
+       $client->configure(array("pipelining" => false, "use_eventloop" => true));
 
        $client->enqueue($request);
        $client->send();
index 884a3c60f23dac9063926e8f9add496e34b7325c..4bf8c48e4d09cc122ae02a2021679fe6079ea120 100644 (file)
@@ -4,6 +4,9 @@ client pipelining
 <?php 
 include "skipif.inc";
 skip_client_test();
+if (version_compare(http\Client\Curl\Versions\CURL, "7.62.0", ">=")) {
+       die("skip CURL_VERSION >= 7.62 -- pipelining disabled\n");
+}
 ?>
 --FILE--
 <?php 
index e819003347b5df71909eae234e8e3e1f1bc84cfd..f262a7ac7c4c9f64d58f693b1d9293efb0a4184b 100644 (file)
@@ -12,103 +12,110 @@ include "helper/server.inc";
 
 echo "Test\n";
 
-function dump($f) {
-       return;
-       readfile($f);
+function dump() {
+       global $tmpfile, $section;
+       printf("# %s\n", $section);
+       foreach (file($tmpfile) as $line) {
+               if ($line{0} === "#" || $line === "\n") {
+                       continue;
+               }
+               printf("%s:\t%s", $tmpfile, $line);
+       }
 }
 
-function cookies($client) {
-       foreach ($client->getResponse()->getCookies() as $cookie) {
-               echo trim($cookie), "\n";
+function send_and_check($client, $cmp) {
+       global $section, $request;
+       $client->requeue($request)->send();
+       foreach ($client->getResponse()->getCookies() as $list) {
+               foreach ($list->getCookies() as $name => $value) {
+                       if ($cmp[$name] != $value) {
+                               printf("# %s\nExpected %s=%s, got %s\n",
+                                       $section, $name, $cmp[$name], $value);
+                       }
+               }
        }
+       #dump();
 }
 
 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
 $request = new http\Client\Request("GET", "http://localhost");
 
+$section = "distinct clients";
+
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 
+$section = "reusing curl handles";
+
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 2]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 3]);
 });
 
+$section = "distict client with persistent cookies";
+
 $request->setOptions(array("cookiestore" => $tmpfile));
 
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
+       send_and_check($client, ["counter" => 2]);
+       send_and_check($client, ["counter" => 3]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 4]);
+       send_and_check($client, ["counter" => 5]);
+       send_and_check($client, ["counter" => 6]);
 });
 
+$section = "distinct client with persistent cookies, but session cookies removed";
+
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port, "cookiesession" => true));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
+       send_and_check($client, ["counter" => 1]);
+       send_and_check($client, ["counter" => 1]);
 });
 
+$section = "distinct client with persistent cookies, and session cookies kept";
+
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port, "cookiesession" => false));
        $client = new http\Client;
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 2]);
+       send_and_check($client, ["counter" => 3]);
+       send_and_check($client, ["counter" => 4]);
 });
 
+$section = "reusing curl handles without persistent cookies and disabling cookie_share";
 
 $c = new http\Client("curl", "test");
 $c->configure(array("share_cookies" => false));
@@ -118,20 +125,17 @@ $request->setOptions(array("cookiestore" => null));
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 server("cookie.inc", function($port) use($request, $tmpfile) {
        $request->setOptions(array("port" => $port));
        $client = new http\Client("curl", "test");
-       cookies($client->requeue($request)->send());
-dump($tmpfile);
+       send_and_check($client, ["counter" => 1]);
 });
 
 
@@ -141,25 +145,4 @@ unlink($tmpfile);
 ===DONE===
 --EXPECT--
 Test
-counter=1;
-counter=1;
-counter=1;
-counter=1;
-counter=2;
-counter=3;
-counter=1;
-counter=2;
-counter=3;
-counter=4;
-counter=5;
-counter=6;
-counter=1;
-counter=1;
-counter=1;
-counter=2;
-counter=3;
-counter=4;
-counter=1;
-counter=1;
-counter=1;
 ===DONE===