diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Pest.php | 6 | ||||
| -rw-r--r-- | tests/Unit/BasicStrategyTest.php | 2 | ||||
| -rw-r--r-- | tests/Utils/TestMiddleware.php | 15 |
3 files changed, 23 insertions, 0 deletions
diff --git a/tests/Pest.php b/tests/Pest.php index b3d9bbc..9ff7c44 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1 +1,7 @@ <?php + +use Lightscale\Router\Test\Utils\TestMiddleware; + +beforeEach(function() { + TestMiddleware::resetCalls(); +}); diff --git a/tests/Unit/BasicStrategyTest.php b/tests/Unit/BasicStrategyTest.php index 2c657d6..9f057c1 100644 --- a/tests/Unit/BasicStrategyTest.php +++ b/tests/Unit/BasicStrategyTest.php @@ -60,7 +60,9 @@ it('runs middleware', function () { expect($result)->toBe($response); $mw1->assertCalled(); + $mw1->assertCallNumber(1); $mw2->assertCalled(); + $mw2->assertCallNumber(2); $handler->assertCalled(); }); diff --git a/tests/Utils/TestMiddleware.php b/tests/Utils/TestMiddleware.php index 2f3ed32..0adb947 100644 --- a/tests/Utils/TestMiddleware.php +++ b/tests/Utils/TestMiddleware.php @@ -11,11 +11,21 @@ use Psr\Http\Message\ServerRequestInterface; class TestMiddleware implements Middleware { + private static int $staticCalls = 0; + + private int $call; private int $calls = 0; + + public static function resetCalls(): void + { + self::$staticCalls = 0; + } + public function handle(ServerRequestInterface $request, callable $next): ResponseInterface { ++$this->calls; + $this->call = ++self::$staticCalls; return $next($request); } @@ -24,4 +34,9 @@ class TestMiddleware implements Middleware { Assert::assertGreaterThan(0, $this->calls); } + + public function assertCallNumber(int $num): void + { + Assert::assertSame($num, $this->call); + } } |
