summaryrefslogtreecommitdiff
path: root/tests/Unit/Middleware/Stub
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Middleware/Stub')
-rw-r--r--tests/Unit/Middleware/Stub/ExceptionMiddlewareHandler.php23
-rw-r--r--tests/Unit/Middleware/Stub/NotARealMiddleware.php8
-rw-r--r--tests/Unit/Middleware/Stub/ReturnResponseMiddleware.php36
-rw-r--r--tests/Unit/Middleware/Stub/ReturnResponseMiddlewareHandler.php30
4 files changed, 97 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/Stub/ExceptionMiddlewareHandler.php b/tests/Unit/Middleware/Stub/ExceptionMiddlewareHandler.php
new file mode 100644
index 00000000..5e374bea
--- /dev/null
+++ b/tests/Unit/Middleware/Stub/ExceptionMiddlewareHandler.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware\Stub;
+
+use Exception;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+class ExceptionMiddlewareHandler implements RequestHandlerInterface
+{
+ /**
+ * Throws an exception
+ *
+ * @param ServerRequestInterface $request
+ * @return ResponseInterface
+ * @throws Exception
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ throw new Exception('Boooom!');
+ }
+}
diff --git a/tests/Unit/Middleware/Stub/NotARealMiddleware.php b/tests/Unit/Middleware/Stub/NotARealMiddleware.php
new file mode 100644
index 00000000..017389da
--- /dev/null
+++ b/tests/Unit/Middleware/Stub/NotARealMiddleware.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware\Stub;
+
+class NotARealMiddleware
+{
+ // I'm not a middleware!
+}
diff --git a/tests/Unit/Middleware/Stub/ReturnResponseMiddleware.php b/tests/Unit/Middleware/Stub/ReturnResponseMiddleware.php
new file mode 100644
index 00000000..7c241353
--- /dev/null
+++ b/tests/Unit/Middleware/Stub/ReturnResponseMiddleware.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware\Stub;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+class ReturnResponseMiddleware implements MiddlewareInterface
+{
+ /** @var ResponseInterface */
+ protected $response;
+
+ public function __construct(ResponseInterface $response)
+ {
+ $this->response = $response;
+ }
+
+ /**
+ * Process an incoming server request and return a response, optionally delegating
+ * response creation to a handler.
+ *
+ * Could be used to group middleware
+ *
+ * @param ServerRequestInterface $request
+ * @param RequestHandlerInterface $handler
+ * @return ResponseInterface
+ */
+ public function process(
+ ServerRequestInterface $request,
+ RequestHandlerInterface $handler
+ ): ResponseInterface {
+ return $this->response;
+ }
+}
diff --git a/tests/Unit/Middleware/Stub/ReturnResponseMiddlewareHandler.php b/tests/Unit/Middleware/Stub/ReturnResponseMiddlewareHandler.php
new file mode 100644
index 00000000..323e07b4
--- /dev/null
+++ b/tests/Unit/Middleware/Stub/ReturnResponseMiddlewareHandler.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware\Stub;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+class ReturnResponseMiddlewareHandler implements RequestHandlerInterface
+{
+ /** @var ResponseInterface */
+ protected $response;
+
+ public function __construct(ResponseInterface $response)
+ {
+ $this->response = $response;
+ }
+
+ /**
+ * Returns a given response
+ *
+ * @param ServerRequestInterface $request
+ * @return ResponseInterface
+ * @throws \Exception
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ return $this->response;
+ }
+}