Passed
Push — main ( 81869f...49082a )
by Chema
58s queued 13s
created

test_run_multiple_route_collections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 20
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Router;
6
7
use Gacela\Router\Entities\Request;
8
use Gacela\Router\Entities\Response;
9
use Gacela\Router\Router;
10
use Gacela\Router\Routes;
11
use GacelaTest\Feature\HeaderTestCase;
12
13
final class RouterRunTest extends HeaderTestCase
14
{
15
    public function test_run_multiple_route_collections(): void
16
    {
17
        $_SERVER['REQUEST_URI'] = 'https://example.org/uri-2';
18
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
19
20
        $router = Router::create();
21
22
        $router->addRoutes(static function (Routes $routes): void {
23
            $routes->get('uri-1', static fn () => new Response('first body'));
24
        });
25
26
        $router->addRoutes(static function (Routes $routes): void {
27
            $routes->get('uri-2', static fn () => new Response('second body'));
28
        });
29
30
        $router->run();
31
32
        $this->expectOutputString('second body');
33
34
        self::assertSame([], $this->headers());
35
    }
36
37
    public function test_run_same_multiple_route_collections_then_first_with_priority(): void
38
    {
39
        $_SERVER['REQUEST_URI'] = 'https://example.org/uri';
40
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
41
42
        $router = Router::create();
43
44
        $router->addRoutes(static function (Routes $routes): void {
45
            $routes->get('uri', static fn () => new Response('first body'));
46
        });
47
48
        $router->addRoutes(static function (Routes $routes): void {
49
            $routes->get('uri', static fn () => new Response('second body'));
50
        });
51
52
        $router->run();
53
54
        $this->expectOutputString('first body');
55
56
        self::assertSame([], $this->headers());
57
    }
58
}
59