From b899a995e2fd977fbf7497b36b2dbc8d641ef398 Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: Started structure for middleware --- tests/Unit/BasicStrategyTest.php | 6 +++++- tests/Unit/MiddlewareTest.php | 19 +++++++++++++++++++ tests/Utils/TestCallable.php | 2 +- tests/Utils/TestMiddleware.php | 27 +++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/Unit/MiddlewareTest.php create mode 100644 tests/Utils/TestMiddleware.php (limited to 'tests') diff --git a/tests/Unit/BasicStrategyTest.php b/tests/Unit/BasicStrategyTest.php index 1f1489a..896858d 100644 --- a/tests/Unit/BasicStrategyTest.php +++ b/tests/Unit/BasicStrategyTest.php @@ -37,8 +37,12 @@ it('calls route', function () { [] )); - $cb->assertIsCalled(); + $cb->assertCalled(); $call = $cb->getLastCall(); expect($call->args[0] ?? null)->toBe($rc); expect($res)->toBe($response); }); + +it('runs middleware', function() { + $factory = new +}); diff --git a/tests/Unit/MiddlewareTest.php b/tests/Unit/MiddlewareTest.php new file mode 100644 index 0000000..d81300d --- /dev/null +++ b/tests/Unit/MiddlewareTest.php @@ -0,0 +1,19 @@ +createServerRequest('get', 'testing'); + $response = $factory->createResponse(); + $middleware = new TestMiddleware; + $handler = new TestCallable(fn() => $response); + $result = $middleware->handle($request, $handler); + $middleware->assertCalled(); + $handler->assertCalled(); + expect($result)->toBe($response); +}); diff --git a/tests/Utils/TestCallable.php b/tests/Utils/TestCallable.php index 526ddf4..67b3d6c 100644 --- a/tests/Utils/TestCallable.php +++ b/tests/Utils/TestCallable.php @@ -51,7 +51,7 @@ class TestCallable return $this->calls[$this->getCallCount() - 1] ?? null; } - public function assertIsCalled(): void + public function assertCalled(): void { Assert::assertGreaterThan(0, $this->getCallCount(), 'Not been called'); } diff --git a/tests/Utils/TestMiddleware.php b/tests/Utils/TestMiddleware.php new file mode 100644 index 0000000..2f3ed32 --- /dev/null +++ b/tests/Utils/TestMiddleware.php @@ -0,0 +1,27 @@ +calls; + + return $next($request); + } + + public function assertCalled(): void + { + Assert::assertGreaterThan(0, $this->calls); + } +} -- cgit v1.2.3