diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Datasets/HttpMethods.php | 11 | ||||
| -rw-r--r-- | tests/Unit/GroupDefinitionTest.php | 10 | ||||
| -rw-r--r-- | tests/Unit/RouterTest.php | 10 |
3 files changed, 22 insertions, 9 deletions
diff --git a/tests/Datasets/HttpMethods.php b/tests/Datasets/HttpMethods.php new file mode 100644 index 0000000..fa90b14 --- /dev/null +++ b/tests/Datasets/HttpMethods.php @@ -0,0 +1,11 @@ +<?php + +declare(strict_types=1); + +use Lightscale\Router\Enums\HttpMethod; + +dataset('http-methods', function (): Generator { + foreach (HttpMethod::cases() as $m) { + yield $m->value => $m; + } +}); diff --git a/tests/Unit/GroupDefinitionTest.php b/tests/Unit/GroupDefinitionTest.php index b8e8063..f11cb87 100644 --- a/tests/Unit/GroupDefinitionTest.php +++ b/tests/Unit/GroupDefinitionTest.php @@ -6,6 +6,7 @@ use Lightscale\Router\Enums\HttpMethod; use Lightscale\Router\Group; use Lightscale\Router\GroupDefinition; use Lightscale\Router\PathSegmentMatch; +use Lightscale\Router\RouteDefinition; use Lightscale\Router\Router; $make = fn () => new GroupDefinition(new Group(new Router(), null)); @@ -25,7 +26,7 @@ it('creates group with name') ->getName()->toBe('name'); it('can make a route', function () { - $router = new Router; + $router = new Router(); $group = (new Group($router, null))->prefix('/test'); $groupDef = new GroupDefinition($group); $groupDef->make(HttpMethod::Get, '/hello/world', fn () => null); @@ -33,3 +34,10 @@ it('can make a route', function () { expect($router->findSegment('/test/hello/world')) ->toBeInstanceOf(PathSegmentMatch::class); }); + +it('returns RouteDefinition when making :dataset route') + ->with('http-methods') + ->expect(fn (HttpMethod $m) => (new GroupDefinition((new Group(new Router(), null))->prefix('/test'))) + ->{$m->value}('/hello', fn () => null) + ) + ->toBeInstanceOf(RouteDefinition::class); diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index 9e9de88..5b11caf 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -234,14 +234,8 @@ 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($methodGenerator) + ->with('http-methods') ->expect(function (HttpMethod $m) { $router = new Router(); $router->{$m->value}($p = '/test1/test2', fn () => null); @@ -257,7 +251,7 @@ it('returns RouteDefinition when making route') ->toBeInstanceOf(RouteDefinition::class); it('returns RouteDefinition when making :dataset route') - ->with($methodGenerator) + ->with('http-methods') ->expect(fn (HttpMethod $m) => (new Router())->{$m->value}('/test', fn () => null)) ->toBeInstanceOf(RouteDefinition::class); |
