summaryrefslogtreecommitdiff
path: root/tests/Unit
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
parent7144cad2df09b68a7359955242aabef746a826b3 (diff)
Created tests for having middleware
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Concerns/HasMiddlewareTest.php35
-rw-r--r--tests/Unit/GroupTest.php2
-rw-r--r--tests/Unit/RouteTest.php2
-rw-r--r--tests/Unit/RouterTest.php4
4 files changed, 37 insertions, 6 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);
diff --git a/tests/Unit/GroupTest.php b/tests/Unit/GroupTest.php
index fc7ead3..58d58d6 100644
--- a/tests/Unit/GroupTest.php
+++ b/tests/Unit/GroupTest.php
@@ -139,5 +139,3 @@ it('gets the name with three ancestors, one without name')
)->name('test2.')
)->name('test3.')->getFullName())
->toBe('test1.test2.test3.');
-
-it('has middleware')->todo();
diff --git a/tests/Unit/RouteTest.php b/tests/Unit/RouteTest.php
index e4501b4..e4ce06d 100644
--- a/tests/Unit/RouteTest.php
+++ b/tests/Unit/RouteTest.php
@@ -53,5 +53,3 @@ it('can get handler', function () {
);
expect($r->getHandler())->toBe($h);
});
-
-it('has middleware')->todo();
diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php
index dcbb599..08664c9 100644
--- a/tests/Unit/RouterTest.php
+++ b/tests/Unit/RouterTest.php
@@ -331,5 +331,5 @@ it('builds routes in groups', function () {
expect($router->getNamedRoute('test4'))->toBe($r4);
});
-it('has middleware')->todo();
-it('can create a group with middleware')->todo();
+it('can create a group with middleware', function () {
+});