Passed
Push — main ( 615377...62c5ea )
by Chema
54s queued 13s
created

RouterConfigTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_root_routes_plugin() 0 8 1
A setUp() 0 9 1
A test_name_routes_plugin() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Config;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Gacela;
9
use Gacela\Router\Config\RouterGacelaConfig;
10
use Gacela\Router\Entities\Request;
11
use Gacela\Router\Router;
12
use Gacela\Router\RouterInterface;
13
use GacelaTest\Feature\Config\Module\Plugin\NameRoutesPlugin;
14
use GacelaTest\Feature\Config\Module\Plugin\RootRoutesPlugin;
15
use GacelaTest\Feature\HeaderTestCase;
16
17
final class RouterConfigTest extends HeaderTestCase
18
{
19
    protected function setUp(): void
20
    {
21
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
22
            $config->resetInMemoryCache();
23
24
            $config->addExtendConfig(RouterGacelaConfig::class);
25
26
            $config->addPlugin(NameRoutesPlugin::class);
27
            $config->addPlugin(RootRoutesPlugin::class);
28
        });
29
    }
30
31
    public function test_root_routes_plugin(): void
32
    {
33
        $_SERVER['REQUEST_URI'] = 'https://example.org/';
34
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
35
36
        Gacela::get(Router::class)->run();
37
38
        $this->expectOutputString(json_encode(['hello' => 'bob?']));
39
    }
40
41
    public function test_name_routes_plugin(): void
42
    {
43
        $_SERVER['REQUEST_URI'] = 'https://example.org/alice';
44
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
45
46
        Gacela::get(RouterInterface::class)->run();
47
48
        $this->expectOutputString(json_encode(['hello' => 'alice']));
49
    }
50
}
51