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

RouterJsonResponseTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_simple_redirect() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Router;
6
7
use Gacela\Router\Entities\JsonResponse;
8
use Gacela\Router\Entities\Request;
9
use Gacela\Router\Router;
10
use Gacela\Router\Routes;
11
use GacelaTest\Feature\HeaderTestCase;
12
13
final class RouterJsonResponseTest extends HeaderTestCase
14
{
15
    public function test_simple_redirect(): void
16
    {
17
        $_SERVER['REQUEST_URI'] = 'https://example.org/optional/uri';
18
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
19
20
        Router::configure(static function (Routes $routes): void {
21
            $routes->get('optional/uri', static fn () => new JsonResponse([
1 ignored issue
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object|string expected by parameter $controller of Gacela\Router\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

21
            $routes->get('optional/uri', /** @scrutinizer ignore-type */ static fn () => new JsonResponse([
Loading history...
22
                'key' => 'value',
23
            ]));
24
        });
25
26
        $this->expectOutputString('{"key":"value"}');
27
28
        self::assertSame([
29
            [
30
                'header' => 'Content-Type: application/json',
31
                'replace' => true,
32
                'response_code' => 0,
33
            ],
34
        ], $this->headers());
35
    }
36
}
37