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

ErrorHandlingTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
c 0
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_match_does_not_matches_other_methods() 0 9 1
A test_respond_status_404_when_the_uri_does_not_matches() 0 15 1
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\Router;
9
use Gacela\Router\Routes;
10
use GacelaTest\Feature\HeaderTestCase;
11
use GacelaTest\Feature\Router\Fixtures\FakeController;
12
13
final class ErrorHandlingTest extends HeaderTestCase
14
{
15
    public function test_match_does_not_matches_other_methods(): void
16
    {
17
        $_SERVER['REQUEST_URI'] = 'https://example.org/expected/uri';
18
        $_SERVER['REQUEST_METHOD'] = 'GET';
19
20
        $this->expectOutputString('');
21
22
        Router::configure(static function (Routes $routes): void {
23
            $routes->post('expected/uri', FakeController::class, 'basicAction');
24
        });
25
    }
26
27
    public function test_respond_status_404_when_the_uri_does_not_matches(): void
28
    {
29
        $_SERVER['REQUEST_URI'] = 'https://example.org/optional/uri';
30
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_OPTIONS;
31
32
        Router::configure(static function (): void {
33
        });
34
35
        self::assertSame([
36
            [
37
                'header' => 'HTTP/1.0 404 Not Found',
38
                'replace' => true,
39
                'response_code' => 0,
40
            ],
41
        ], $this->headers());
42
    }
43
}
44