Passed
Push — main ( af49ee...deaffd )
by Chema
02:30
created

RouterConfigTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 33
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_root_route_plugin() 0 8 1
A setUp() 0 9 1
A test_name_route_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
            $config->extendGacelaConfig(RouterGacelaConfig::class);
24
25
            $config->addPlugins([
26
                NameRoutesPlugin::class,
27
                RootRoutesPlugin::class,
28
            ]);
29
        });
30
    }
31
32
    public function test_root_route_plugin(): void
33
    {
34
        $_SERVER['REQUEST_URI'] = 'https://example.org/';
35
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
36
37
        Gacela::get(Router::class)->run();
38
39
        $this->expectOutputString(json_encode(['hello' => 'bob?']));
40
    }
41
42
    public function test_name_route_plugin(): void
43
    {
44
        $_SERVER['REQUEST_URI'] = 'https://example.org/alice';
45
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
46
47
        Gacela::get(RouterInterface::class)->run();
48
49
        $this->expectOutputString(json_encode(['hello' => 'alice']));
50
    }
51
}
52