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
![]() |
|||||
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
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
![]() |
|||||
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
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
![]() |
|||||
46 | }); |
||||
47 | |||||
48 | $router->configure(static function (Routes $routes): void { |
||||
49 | $routes->get('uri', static fn () => new Response('second body')); |
||||
0 ignored issues
–
show
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
![]() |
|||||
50 | }); |
||||
51 | |||||
52 | $router->run(); |
||||
53 | |||||
54 | $this->expectOutputString('first body'); |
||||
55 | |||||
56 | self::assertSame([], $this->headers()); |
||||
57 | } |
||||
58 | } |
||||
59 |