summaryrefslogtreecommitdiff
path: root/tests/Unit/Concerns/HasMiddlewareTest.php
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:00:33 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:00:33 +0100
commit65bb048bf3c3d4226b8d7580592b62351e07a7e6 (patch)
tree0ecdfd77213af25ac27a4ad3b5e7f48a0157b099 /tests/Unit/Concerns/HasMiddlewareTest.php
parent7144cad2df09b68a7359955242aabef746a826b3 (diff)
Created tests for having middleware
Diffstat (limited to 'tests/Unit/Concerns/HasMiddlewareTest.php')
-rw-r--r--tests/Unit/Concerns/HasMiddlewareTest.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/Unit/Concerns/HasMiddlewareTest.php b/tests/Unit/Concerns/HasMiddlewareTest.php
new file mode 100644
index 0000000..8aaac15
--- /dev/null
+++ b/tests/Unit/Concerns/HasMiddlewareTest.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+use Lightscale\Router\Enums\HttpMethod;
+use Lightscale\Router\Group;
+use Lightscale\Router\Route;
+use Lightscale\Router\Router;
+use Lightscale\Router\Test\Utils\TestMiddleware;
+
+$classes = [
+ Router::class => fn () => new Router(),
+ Group::class => fn () => new Group(new Router(), null),
+ Route::class => fn () => new Route(HttpMethod::Get, fn () => null),
+];
+
+test(':dataset has middleware', function ($inst) {
+ $inst->addMiddleware($mw1 = new TestMiddleware());
+
+ expect($inst->getMiddleware())
+ ->toHaveCount(1)
+ ->{0}->toBe($mw1);
+})->with($classes);
+
+test(':dataset adds array of middleware', function ($inst) {
+ $inst->addMiddleware([
+ $mw1 = new TestMiddleware(),
+ $mw2 = new TestMiddleware(),
+ ]);
+
+ expect($inst->getMiddleware())
+ ->toHaveCount(2)
+ ->{0}->toBe($mw1)
+ ->{1}->toBe($mw2);
+})->with($classes);