summaryrefslogtreecommitdiff
path: root/tests/Unit/GroupDefinitionTest.php
blob: b8e8063962887b92e924cc59828b64c7f1c1c021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

declare(strict_types=1);

use Lightscale\Router\Enums\HttpMethod;
use Lightscale\Router\Group;
use Lightscale\Router\GroupDefinition;
use Lightscale\Router\PathSegmentMatch;
use Lightscale\Router\Router;

$make = fn () => new GroupDefinition(new Group(new Router(), null));

it('initializes')
    ->expect(fn () => $make())
    ->toBeInstanceOf(GroupDefinition::class);

it('creates group with prefix')
    ->expect(fn () => $make()->prefix('/test'))
    ->toBeInstanceOf(Group::class)
    ->getPrefix()->toBe('/test');

it('creates group with name')
    ->expect(fn () => $make()->name('name'))
    ->toBeInstanceOf(Group::class)
    ->getName()->toBe('name');

it('can make a route', function () {
    $router = new Router;
    $group = (new Group($router, null))->prefix('/test');
    $groupDef = new GroupDefinition($group);
    $groupDef->make(HttpMethod::Get, '/hello/world', fn () => null);

    expect($router->findSegment('/test/hello/world'))
        ->toBeInstanceOf(PathSegmentMatch::class);
});