Passed
Pull Request — main (#19)
by Chema
02:31
created

RouterTest::test_dynamic_get_route_found()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightningTest\Unit\Router;
6
7
use PhpLightning\Router\Router;
8
use PHPUnit\Framework\TestCase;
9
10
final class RouterTest extends TestCase
11
{
12
    public function test_404_no_route_found(): void
13
    {
14
        $router = Router::withServer([
15
            'REQUEST_METHOD' => 'GET',
16
            'REQUEST_URI' => '/foo/?bar=123000',
17
        ]);
18
19
        $router->listen();
20
21
        $this->expectOutputString("404: route '/foo' not found");
22
    }
23
24
    public function test_static_get_route_found(): void
25
    {
26
        $router = Router::withServer([
27
            'REQUEST_METHOD' => 'GET',
28
            'REQUEST_URI' => '/foo/?bar=123000',
29
        ]);
30
        $router->get('/foo', static function (): void {
31
            echo 'route found';
32
        });
33
34
        $router->listen();
35
36
        $this->expectOutputString('route found');
37
    }
38
39
    public function test_dynamic_get_route_found(): void
40
    {
41
        $router = Router::withServer([
42
            'REQUEST_METHOD' => 'GET',
43
            'REQUEST_URI' => '/foo/?bar=123000',
44
        ]);
45
46
        $router->get('/$name', static function (string $name): void {
47
            echo "route '{$name}' found";
48
        });
49
50
        $router->listen();
51
52
        $this->expectOutputString("route 'foo' found");
53
    }
54
}
55