summaryrefslogtreecommitdiff
path: root/php-src/tests/http
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-11 14:57:47 +0300
committerWolfy-J <[email protected]>2018-06-11 14:57:47 +0300
commit846cec64f177a9cfef016a8225c4fae0faa29a0c (patch)
treea0dc1df41ab25793a2dd5ada80f3ca5de4615e7d /php-src/tests/http
parent78fb74cfa5c0156f70c095a4f2cfee9851a9dc0f (diff)
more tests for http
Diffstat (limited to 'php-src/tests/http')
-rw-r--r--php-src/tests/http/client.php45
-rw-r--r--php-src/tests/http/echo.php10
-rw-r--r--php-src/tests/http/header.php9
3 files changed, 64 insertions, 0 deletions
diff --git a/php-src/tests/http/client.php b/php-src/tests/http/client.php
new file mode 100644
index 00000000..3b6b5dc6
--- /dev/null
+++ b/php-src/tests/http/client.php
@@ -0,0 +1,45 @@
+<?php
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+ini_set('display_errors', 'stderr');
+require dirname(__DIR__) . "/../../vendor/autoload.php";
+
+if (count($argv) < 3) {
+ die("need 2 arguments");
+}
+
+list($test, $goridge) = [$argv[1], $argv[2]];
+
+switch ($goridge) {
+ case "pipes":
+ $relay = new Goridge\StreamRelay(STDIN, STDOUT);
+ break;
+
+ case "tcp":
+ $relay = new Goridge\SocketRelay("localhost", 9007);
+ break;
+
+ case "unix":
+ $relay = new Goridge\SocketRelay(
+ "sock.unix",
+ null,
+ Goridge\SocketRelay::SOCK_UNIX
+ );
+ break;
+
+ default:
+ die("invalid protocol selection");
+}
+
+$psr7 = new RoadRunner\PSR7Client(new RoadRunner\Worker($relay));
+require_once sprintf("%s/%s.php", __DIR__, $test);
+
+while ($req = $psr7->acceptRequest()) {
+ try {
+ $psr7->respond(handleRequest($req, new \Zend\Diactoros\Response()));
+ } catch (\Throwable $e) {
+ $psr7->getWorker()->error((string)$e);
+ }
+}
diff --git a/php-src/tests/http/echo.php b/php-src/tests/http/echo.php
new file mode 100644
index 00000000..eeccc7e5
--- /dev/null
+++ b/php-src/tests/http/echo.php
@@ -0,0 +1,10 @@
+<?php
+
+use \Psr\Http\Message\ServerRequestInterface;
+use \Psr\Http\Message\ResponseInterface;
+
+function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
+{
+ $resp->getBody()->write(strtoupper($req->getQueryParams()['hello']));
+ return $resp;
+} \ No newline at end of file
diff --git a/php-src/tests/http/header.php b/php-src/tests/http/header.php
new file mode 100644
index 00000000..9bb15ccd
--- /dev/null
+++ b/php-src/tests/http/header.php
@@ -0,0 +1,9 @@
+<?php
+
+use \Psr\Http\Message\ServerRequestInterface;
+use \Psr\Http\Message\ResponseInterface;
+
+function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
+{
+ return $resp->withAddedHeader("Header", $req->getQueryParams()['hello']);
+} \ No newline at end of file