diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
| commit | f11839200e2133bde89b96859d13e1ed67f1d3bf (patch) | |
| tree | a581285e4761f214ef1d847492d47f5496ed1721 /tests/Unit/RouterTest.php | |
| parent | 00c99f6c0e5af2564b467bda2b824fe4152261f8 (diff) | |
Router tests for creating routes
Diffstat (limited to 'tests/Unit/RouterTest.php')
| -rw-r--r-- | tests/Unit/RouterTest.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index dc78f56..c6d5163 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -183,3 +183,42 @@ it('calls strategy runRoute with dispatch on match', function () { $result = $router->dispatch($request); expect($result)->toBe($response); }); + +it('make a route', function () { + $router = new Router(); + + $router->route(HttpMethod::Get, '/test1/test2/test3', fn () => null); + + expect($router->findRoute(HttpMethod::Get, '/test1/test2/test3')) + ->toBeInstanceOf(RouteMatch::class); +}); + +it('makes a get route', function () { + $router = new Router(); + $router->get('/test1/test2', fn () => null); + + expect($router->findRoute(HttpMethod::Get, '/test1/test2')) + ->toBeInstanceOf(RouteMatch::class); +}); + +it('makes a post route', function () { + $router = new Router(); + $router->post('/test1/test2', fn () => null); + + expect($router->findRoute(HttpMethod::Post, '/test1/test2')) + ->toBeInstanceOf(RouteMatch::class); +}); + +it('makes a :dataset route') + ->with(function (): Generator { + foreach (HttpMethod::cases() as $m) { + yield $m->value => $m; + } + }) + ->expect(function (HttpMethod $m) { + $router = new Router(); + $router->{$m->value}($p = '/test1/test2', fn () => null); + + return $router->findRoute($m, $p); + }) + ->toBeInstanceOf(RouteMatch::class); |
