fix tests
authorMichael Wallner <mike@php.net>
Fri, 22 Mar 2019 12:37:17 +0000 (13:37 +0100)
committerMichael Wallner <mike@php.net>
Fri, 22 Mar 2019 12:37:17 +0000 (13:37 +0100)
tests/client009.phpt
tests/client010.phpt
tests/client011.phpt
tests/client017.phpt
tests/clientresponse001.phpt
tests/clientresponse002.phpt
tests/helper/cookie1.inc [new file with mode: 0644]
tests/helper/cookie2.inc [new file with mode: 0644]
tests/helper/env.inc [new file with mode: 0644]

index 9b5579dc71994a80f94a6d1c9ec903c1ad99fc1f..6aea2255cd35b2654550f248f446597ca7a3c87a 100644 (file)
@@ -3,33 +3,38 @@ client static cookies
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.print_request.php");
+include "helper/server.inc";
+
+echo "Test\n";
 
 function x($a) {
        $r[key($a)]=end($a);
        $r[key($a)]=reset($a);
        return $r;
 }
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->setCookies(array("test" => "bar"));
-       $client->addCookies(array("foo" => "test"));
-       $client->enqueue($request);
-       $client->send();
-       var_dump($client->getResponse()->getBody()->toString());
-       $request->setOptions(array("cookies" => x($client->getCookies())));
-       $client->requeue($request);
-       $client->send();
-       var_dump($client->getResponse()->getBody()->toString());
-}
 
+server("env.inc", function($port) {
+
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->setCookies(array("test" => "bar"));
+               $client->addCookies(array("foo" => "test"));
+               $client->enqueue($request);
+               $client->send();
+               var_dump($client->getResponse()->getBody()->toString());
+               $request->setOptions(array("cookies" => x($client->getCookies())));
+               $client->requeue($request);
+               $client->send();
+               var_dump($client->getResponse()->getBody()->toString());
+       }
+});
 ?>
 Done
 --EXPECTREGEX--
index 86f9c8c94da026c364e2fe557c64901c9ddbc551..0c25c1638cf70eccff6930b73acf1b621cd51538 100644 (file)
@@ -3,13 +3,14 @@ client upload
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
+include "helper/server.inc";
+
+echo "Test\n";
 $RE =
 '/(Array
 \(
@@ -17,25 +18,27 @@ $RE =
         \(
             \[name\] \=\> client010\.php
             \[type\] \=\> text\/plain
-            \[tmp_name\] \=\> .+
-            \[error\] \=\> 0
             \[size\] \=\> \d+
         \)
 
 \)
 )+/';
-$request = new http\Client\Request("POST", "http://dev.iworks.at/ext-http/.print_request.php");
-$request->getBody()->addForm(null, array("file"=>__FILE__, "name"=>"upload", "type"=>"text/plain"));
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->enqueue($request)->send();
-       if (!preg_match($RE, $s = $client->getResponse()->getBody()->toString())) {
-               echo($s);
+server("env.inc", function($port) use($RE) {
+
+       $request = new http\Client\Request("POST", "http://localhost:$port");
+       $request->getBody()->addForm(null, array("file"=>__FILE__, "name"=>"upload", "type"=>"text/plain"));
+
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->enqueue($request)->send();
+               if (!preg_match($RE, $s = $client->getResponse()->getBody()->toString())) {
+                       echo($s);
+               }
        }
-}
+});
 ?>
 Done
 --EXPECT--
 Test
-Done
\ No newline at end of file
+Done
index 59097420c72f5b35d63469a9d3fa588f4ed231af..b1214c440c0d8d674c9af21251fa8880a5c52f1a 100644 (file)
@@ -3,72 +3,68 @@ client history
 --SKIPIF--
 <?php 
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php 
 
-echo "Test\n";
+include "helper/server.inc";
 
-$body = new http\Message\Body;
-$body->append("foobar");
+echo "Test\n";
 
-$request = new http\Client\Request;
-$request->setBody($body);
-$request->setRequestMethod("POST");
-$request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
+server("env.inc", function($port) {
+       $body = new http\Message\Body;
+       $body->append("foobar");
 
-$client = new http\Client;
-$client->recordHistory = true;
+       $request = new http\Client\Request;
+       $request->setBody($body);
+       $request->setRequestMethod("POST");
+       $request->setRequestUrl("http://localhost:$port");
 
-$client->enqueue($request)->send();
-echo $client->getHistory()->toString(true);
+       $client = new http\Client;
+       $client->recordHistory = true;
 
-$client->requeue($request)->send();
-echo $client->getHistory()->toString(true);
+       $client->enqueue($request)->send();
+       echo $client->getHistory()->toString(true);
 
+       $client->requeue($request)->send();
+       echo $client->getHistory()->toString(true);
+});
 ?>
 Done
 --EXPECTF--
 Test
-POST http://dev.iworks.at/ext-http/.print_request.php HTTP/1.1
+POST http://localhost:%d/ HTTP/1.1
 Content-Length: 6
 
 foobar
 HTTP/1.1 200 OK
-Vary: %s
-Content-Type: text/html
-Date: %s
-Server: %s
+Accept-Ranges: bytes
+X-Request-Content-Length: 6
 X-Original-Transfer-Encoding: chunked
 Content-Length: 19
 
 string(6) "foobar"
 
-POST http://dev.iworks.at/ext-http/.print_request.php HTTP/1.1
+POST http://localhost:%d/ HTTP/1.1
 Content-Length: 6
 
 foobar
 HTTP/1.1 200 OK
-Vary: %s
-Content-Type: text/html
-Date: %s
-Server: %s
+Accept-Ranges: bytes
+X-Request-Content-Length: 6
 X-Original-Transfer-Encoding: chunked
 Content-Length: 19
 
 string(6) "foobar"
 
-POST http://dev.iworks.at/ext-http/.print_request.php HTTP/1.1
+POST http://localhost:%d/ HTTP/1.1
 Content-Length: 6
 
 foobar
 HTTP/1.1 200 OK
-Vary: %s
-Content-Type: text/html
-Date: %s
-Server: %s
+Accept-Ranges: bytes
+X-Request-Content-Length: 6
 X-Original-Transfer-Encoding: chunked
 Content-Length: 19
 
index a50502803590a0e93c366f51569127b3503ea391..833287a6b2b3824362f2343102089138c9fbc433 100644 (file)
@@ -3,31 +3,36 @@ client request gzip
 --SKIPIF--
 <?php 
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php 
 
-echo "Test\n";
+include "helper/server.inc";
 
-$client = new http\Client;
-$client->setOptions(array("compress" => true));
+echo "Test\n";
 
-$client->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.print_request.php"));
-$client->send();
+server("env.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port/");
+       
+       $client = new http\Client;
+       $client->setOptions(array("compress" => true));
 
-echo $client->getResponse();
+       $client->enqueue($request);
+       $client->send();
 
+       echo $client->getResponse();
+});
 ?>
 ===DONE===
 --EXPECTF--
 Test
 HTTP/1.1 200 OK
+Accept-Ranges: bytes
+X-Request-Content-Length: 0
 Vary: Accept-Encoding
-Content-Type: text/html
-Date: %s
-Server: %s
+Etag: "%s"
 X-Original-Transfer-Encoding: chunked
-X-Original-Content-Encoding: gzip
-===DONE===
\ No newline at end of file
+X-Original-Content-Encoding: deflate
+===DONE===
+
index 705ee2e3e173ef83c477ba260a67ed173280a851..85f686103ed68764b637f87cb53457e5b908fa1a 100644 (file)
@@ -3,21 +3,25 @@ client response cookie
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie1.php");
+include "helper/server.inc";
+
+echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
-               var_dump($cookies->toArray());
+server("cookie1.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
+                       var_dump($cookies->toArray());
+               }
        }
-}
+});
 ?>
 Done
 --EXPECTREGEX--
index 8c57355b46b016cbfc64fca948b44c83add6f6a0..def4b3f5082cb2efa4739127f25108ce65b3548d 100644 (file)
@@ -3,21 +3,25 @@ client response cookies
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
 skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php");
+include "helper/server.inc";
+
+echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
-               var_dump($cookies->toArray());
+server("cookie2.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               foreach($client->enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) {
+                       var_dump($cookies->toArray());
+               }
        }
-}
+});
 ?>
 Done
 --EXPECTREGEX--
diff --git a/tests/helper/cookie1.inc b/tests/helper/cookie1.inc
new file mode 100644 (file)
index 0000000..0e0d20b
--- /dev/null
@@ -0,0 +1,13 @@
+<?php 
+
+include "server.inc";
+
+serve(function($client) {
+       $request = new http\Message($client, false);
+       $cookies = new http\Cookie();
+       $cookies->setCookie("foo", "bar");
+       $cookies->setCookie("bar", "foo");
+       $response = new http\Env\Response;
+       $response->setCookie($cookies);
+       $response->send($client);
+});
diff --git a/tests/helper/cookie2.inc b/tests/helper/cookie2.inc
new file mode 100644 (file)
index 0000000..0abcb19
--- /dev/null
@@ -0,0 +1,17 @@
+<?php 
+
+include "server.inc";
+
+serve(function($client) {
+       $request = new http\Message($client, false);
+       $response = new http\Env\Response;
+       $old_cookies = new http\Cookie($request->getHeader("Cookie"));
+       $new_cookies = new http\Cookie;
+       $new_cookies->setCookie("temp", $old_cookies->getCookie("temp") ?: microtime(true));
+       $response->setCookie($new_cookies);
+       $new_cookies = new http\Cookie;
+       $new_cookies->setCookie("perm", $old_cookies->getCookie("perm") ?: microtime(true));
+       $new_cookies->setExpires(time()+3600);
+       $response->setCookie($new_cookies);
+       $response->send($client);
+});
diff --git a/tests/helper/env.inc b/tests/helper/env.inc
new file mode 100644 (file)
index 0000000..bedd3a3
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+include "dump.inc";
+include "server.inc";
+
+serve(function($client) {
+       $request = new http\Message($client, false);
+       $response = new http\Env\Response;
+       $response->setEnvRequest($request);
+       $response->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP);
+       $response->setHeader("X-Request-Content-Length", $request->getBody()->stat("size"));
+       ob_start($response);
+       if ($request->isMultipart()) {
+               $files = [];
+               foreach ($request->splitMultipartBody() as $part) {
+                       $cd = $part->getHeader("Content-Disposition", http\Header::class)->getParams();
+                       foreach ($cd->params as $key => $val) {
+                               if ($key === "form-data" && $val["value"] === true) {
+                                       if (isset($val["arguments"]["filename"])) {
+                                               $files[$val["arguments"]["name"]] = [
+                                                       "name" => $val["arguments"]["filename"],
+                                                       "type" => $part->getHeader("Content-Type"),
+                                                       "size" => $part->getBody()->stat("s"),
+                                               ];
+                                       }
+                               }
+                       }
+                       print_r($files);
+               }
+       } else {
+               if (($c = $request->getHeader("Cookie"))) {
+                       print_r((new http\Cookie($c))->getCookies());
+               }
+               if ($request->getBody()->stat("s")) {
+                       var_dump($request->getBody()->toString());
+               }
+       }
+       ob_end_flush();
+       $response->send($client);
+});