RouterRunTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 44
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_run_same_multiple_route_collections_then_first_with_priority() 0 20 1
A test_run_multiple_route_collections() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Router;
6
7
use Gacela\Router\Configure\Routes;
8
use Gacela\Router\Entities\Request;
9
use Gacela\Router\Entities\Response;
10
use Gacela\Router\Router;
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 = new Router();
21
22
        $router->configure(static function (Routes $routes): void {
23
            $routes->get('uri-1', static fn () => new Response('first body'));
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object|string expected by parameter $controller of Gacela\Router\Configure\Routes::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
            $routes->get('uri-1', /** @scrutinizer ignore-type */ static fn () => new Response('first body'));
Loading history...
24
        });
25
26
        $router->configure(static function (Routes $routes): void {
27
            $routes->get('uri-2', static fn () => new Response('second body'));
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object|string expected by parameter $controller of Gacela\Router\Configure\Routes::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            $routes->get('uri-2', /** @scrutinizer ignore-type */ static fn () => new Response('second body'));
Loading history...
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 = new Router();
43
44
        $router->configure(static function (Routes $routes): void {
45
            $routes->get('uri', static fn () => new Response('first body'));
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object|string expected by parameter $controller of Gacela\Router\Configure\Routes::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            $routes->get('uri', /** @scrutinizer ignore-type */ static fn () => new Response('first body'));
Loading history...
46
        });
47
48
        $router->configure(static function (Routes $routes): void {
49
            $routes->get('uri', static fn () => new Response('second body'));
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object|string expected by parameter $controller of Gacela\Router\Configure\Routes::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            $routes->get('uri', /** @scrutinizer ignore-type */ static fn () => new Response('second body'));
Loading history...
50
        });
51
52
        $router->run();
53
54
        $this->expectOutputString('first body');
55
56
        self::assertSame([], $this->headers());
57
    }
58
}
59