From 984753a9c35c3da8262c9bb415c61dd7b2571fd3 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 22 Mar 2019 13:37:17 +0100 Subject: [PATCH] fix tests --- tests/client009.phpt | 35 +++++++++++++---------- tests/client010.phpt | 29 ++++++++++--------- tests/client011.phpt | 54 +++++++++++++++++------------------- tests/client017.phpt | 29 +++++++++++-------- tests/clientresponse001.phpt | 20 +++++++------ tests/clientresponse002.phpt | 20 +++++++------ tests/helper/cookie1.inc | 13 +++++++++ tests/helper/cookie2.inc | 17 ++++++++++++ tests/helper/env.inc | 40 ++++++++++++++++++++++++++ 9 files changed, 172 insertions(+), 85 deletions(-) create mode 100644 tests/helper/cookie1.inc create mode 100644 tests/helper/cookie2.inc create mode 100644 tests/helper/env.inc diff --git a/tests/client009.phpt b/tests/client009.phpt index 9b5579d..6aea225 100644 --- a/tests/client009.phpt +++ b/tests/client009.phpt @@ -3,33 +3,38 @@ client static cookies --SKIPIF-- --FILE-- 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-- diff --git a/tests/client010.phpt b/tests/client010.phpt index 86f9c8c..0c25c16 100644 --- a/tests/client010.phpt +++ b/tests/client010.phpt @@ -3,13 +3,14 @@ client upload --SKIPIF-- --FILE-- 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 diff --git a/tests/client011.phpt b/tests/client011.phpt index 5909742..b1214c4 100644 --- a/tests/client011.phpt +++ b/tests/client011.phpt @@ -3,72 +3,68 @@ client history --SKIPIF-- --FILE-- 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 diff --git a/tests/client017.phpt b/tests/client017.phpt index a505028..833287a 100644 --- a/tests/client017.phpt +++ b/tests/client017.phpt @@ -3,31 +3,36 @@ client request gzip --SKIPIF-- --FILE-- 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=== + diff --git a/tests/clientresponse001.phpt b/tests/clientresponse001.phpt index 705ee2e..85f6861 100644 --- a/tests/clientresponse001.phpt +++ b/tests/clientresponse001.phpt @@ -3,21 +3,25 @@ client response cookie --SKIPIF-- --FILE-- 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-- diff --git a/tests/clientresponse002.phpt b/tests/clientresponse002.phpt index 8c57355..def4b3f 100644 --- a/tests/clientresponse002.phpt +++ b/tests/clientresponse002.phpt @@ -3,21 +3,25 @@ client response cookies --SKIPIF-- --FILE-- 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 index 0000000..0e0d20b --- /dev/null +++ b/tests/helper/cookie1.inc @@ -0,0 +1,13 @@ +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 index 0000000..0abcb19 --- /dev/null +++ b/tests/helper/cookie2.inc @@ -0,0 +1,17 @@ +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 index 0000000..bedd3a3 --- /dev/null +++ b/tests/helper/env.inc @@ -0,0 +1,40 @@ +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); +}); -- 2.30.2