summaryrefslogtreecommitdiff
path: root/tests/Unit/PathSegmentTest.php
blob: 1d19e0e946f3a0d550c45ddd356724bc3435ea45 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

declare(strict_types=1);

use Lightscale\Router\PathSegment;

it('initializes')
    ->expect(fn () => new PathSegment('test'))
    ->toBeInstanceOf(PathSegment::class);

it('can get the content')
    ->expect(fn () => (new PathSegment('test'))->getContent())
    ->toBe('test');

it('can get the parent')
    ->expect(fn () => (new PathSegment(
        'test1',
        new PathSegment('test2')
    ))->getParent())
    ->toBeInstanceOf(PathSegment::class)
    ->getContent()->toBe('test2');

it('has null parent by default')
    ->expect(fn () => (new PathSegment('test'))->getParent())
    ->toBeNull();

$testChain = fn () => new PathSegment(
    'test3',
    new PathSegment(
        'test2',
        new PathSegment(
            'test1'
        )
    )
);

it('can get all ancestors')
    ->expect(fn () => $testChain()->getAncestors())
    ->toBeArray()
    ->toContainOnlyInstancesOf(PathSegment::class)
    ->toHaveCount(2);

it('order all ancestors root first')
    ->expect(fn () => $testChain()->getAncestors())
    ->{0}->getContent()->toBe('test1')
    ->{1}->getContent()->toBe('test2');

it('can get all ancestors and self')
    ->expect(fn () => $testChain()->getAncestorsAndSelf())
    ->toBeArray()
    ->toContainOnlyInstancesOf(PathSegment::class)
    ->toHaveCount(3);

it('order all ancestors and self root first')
    ->expect(fn () => $testChain()->getAncestorsAndSelf())
    ->{0}->getContent()->toBe('test1')
    ->{1}->getContent()->toBe('test2')
    ->{2}->getContent()->toBe('test3');

it('can have children')->todo();

it('can build full path')->todo();

it('can have routes')->todo();

it('can get routes by method')->todo();

it('can get routes for all methods')->todo();