summaryrefslogtreecommitdiff
path: root/tests/Unit/RouterTest.php
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
commit7f3ad6625e00e39cad47cbfca97e6b872712d10a (patch)
treed3e5880f96eb70d4a32d023971ac3bf3531d163c /tests/Unit/RouterTest.php
parent8abfce2091e9665af93a920aed246e3b04abc2aa (diff)
Route methods now return RouteDefinition class and testing
Diffstat (limited to 'tests/Unit/RouterTest.php')
-rw-r--r--tests/Unit/RouterTest.php24
1 files changed, 19 insertions, 5 deletions
diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php
index c6d5163..31e391d 100644
--- a/tests/Unit/RouterTest.php
+++ b/tests/Unit/RouterTest.php
@@ -9,6 +9,7 @@ use Lightscale\Router\Enums\PathSegmentType;
use Lightscale\Router\PathSegment;
use Lightscale\Router\Route;
use Lightscale\Router\RouteCall;
+use Lightscale\Router\RouteDefinition;
use Lightscale\Router\RouteMatch;
use Lightscale\Router\Router;
use Nyholm\Psr7\Factory\Psr17Factory;
@@ -209,12 +210,14 @@ it('makes a post route', function () {
->toBeInstanceOf(RouteMatch::class);
});
+$methodGenerator = function (): Generator {
+ foreach (HttpMethod::cases() as $m) {
+ yield $m->value => $m;
+ }
+};
+
it('makes a :dataset route')
- ->with(function (): Generator {
- foreach (HttpMethod::cases() as $m) {
- yield $m->value => $m;
- }
- })
+ ->with($methodGenerator)
->expect(function (HttpMethod $m) {
$router = new Router();
$router->{$m->value}($p = '/test1/test2', fn () => null);
@@ -222,3 +225,14 @@ it('makes a :dataset route')
return $router->findRoute($m, $p);
})
->toBeInstanceOf(RouteMatch::class);
+
+it('returns RouteDefinition when making route')
+ ->expect(fn() => (new Router())
+ ->route(HttpMethod::Get, '/test', fn() => null)
+ )
+ ->toBeInstanceOf(RouteDefinition::class);
+
+it('returns RouteDefinition when making :dataset route')
+ ->with($methodGenerator)
+ ->expect(fn (HttpMethod $m) => (new Router)->{$m->value}('/test', fn() => null))
+ ->toBeInstanceOf(RouteDefinition::class);