Passed
Push — main ( e120fa...565e18 )
by Chema
53s queued 13s
created

RouterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_404_no_route_found() 0 5 1
A setUp() 0 5 1
A test_dynamic_get_route_found() 0 9 1
A test_static_get_route_found() 0 9 1
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
    private Router $router;
13
14
    protected function setUp(): void
15
    {
16
        $this->router = Router::withServer([
17
            'REQUEST_METHOD' => 'GET',
18
            'REQUEST_URI' => '/foo/?bar=123',
19
        ]);
20
    }
21
22
    public function test_404_no_route_found(): void
23
    {
24
        $this->router->listen();
25
26
        $this->expectOutputString("404: route '/foo' not found");
27
    }
28
29
    public function test_static_get_route_found(): void
30
    {
31
        $this->router->get('/foo', static function (): void {
32
            echo 'route found';
33
        });
34
35
        $this->router->listen();
36
37
        $this->expectOutputString('route found');
38
    }
39
40
    public function test_dynamic_get_route_found(): void
41
    {
42
        $this->router->get('/$name', static function (string $name): void {
43
            echo "route '{$name}' found";
44
        });
45
46
        $this->router->listen();
47
48
        $this->expectOutputString("route 'foo' found");
49
    }
50
}
51