From 25d0c98dd7b69695d0b2a8aa24d991359b371455 Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: added named routes to router --- tests/Unit/RouterTest.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index 31e391d..41b794d 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -227,12 +227,32 @@ it('makes a :dataset route') ->toBeInstanceOf(RouteMatch::class); it('returns RouteDefinition when making route') - ->expect(fn() => (new Router()) - ->route(HttpMethod::Get, '/test', fn() => null) + ->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)) + ->expect(fn (HttpMethod $m) => (new Router())->{$m->value}('/test', fn () => null)) ->toBeInstanceOf(RouteDefinition::class); + +it('has named routes', function () { + $router = new Router(); + $route = new Route(HttpMethod::Get, fn () => null); + $router->addNamedRoute('hello-hello', $route); + + expect($router->getNamedRoute('hello-hello'))->toBe($route); +}); + +it('overrides existing named routes', function () { + $router = new Router(); + $route1 = new Route(HttpMethod::Get, fn () => null); + $route2 = new Route(HttpMethod::Post, fn () => null); + $router->addNamedRoute('hello-hello', $route1); + $router->addNamedRoute('hello-hello', $route2); + + expect($router->getNamedRoute('hello-hello')) + ->not->toBe($route1) + ->toBe($route2); +}); -- cgit v1.2.3