diff options
Diffstat (limited to 'php-src/tests/http')
-rw-r--r-- | php-src/tests/http/client.php | 45 | ||||
-rw-r--r-- | php-src/tests/http/echo.php | 10 | ||||
-rw-r--r-- | php-src/tests/http/header.php | 9 |
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 |