Passed
Push — main ( 053125...2aad05 )
by Chema
57s queued 15s
created

RouterResponseTest::test_string_response()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
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\Entities\Response;
10
use Gacela\Router\Router;
11
use Gacela\Router\Routes;
12
use GacelaTest\Feature\HeaderTestCase;
13
14
final class RouterResponseTest extends HeaderTestCase
15
{
16
    public function test_string_response(): void
17
    {
18
        $_SERVER['REQUEST_URI'] = 'https://example.org/uri';
19
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
20
21
        Router::configure(static function (Routes $routes): void {
22
            $routes->get('uri', static fn () => new Response('body'));
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

22
            $routes->get('uri', /** @scrutinizer ignore-type */ static fn () => new Response('body'));
Loading history...
23
        });
24
25
        $this->expectOutputString('body');
26
27
        self::assertSame([], $this->headers());
28
    }
29
30
    public function test_json_response(): void
31
    {
32
        $_SERVER['REQUEST_URI'] = 'https://example.org/uri';
33
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
34
35
        Router::configure(static function (Routes $routes): void {
36
            $routes->get('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

36
            $routes->get('uri', /** @scrutinizer ignore-type */ static fn () => new JsonResponse([
Loading history...
37
                'key' => 'value',
38
            ]));
39
        });
40
41
        $this->expectOutputString('{"key":"value"}');
42
43
        self::assertSame([
44
            [
45
                'header' => 'Content-Type: application/json',
46
                'replace' => true,
47
                'response_code' => 0,
48
            ],
49
        ], $this->headers());
50
    }
51
}
52