RouterConfigTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_root_route_plugin() 0 10 1
A setUp() 0 9 1
A test_name_route_plugin() 0 10 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 GacelaTest\Feature\Config\Module\Plugin\NameRoutesPlugin;
13
use GacelaTest\Feature\Config\Module\Plugin\RootRoutesPlugin;
14
use GacelaTest\Feature\HeaderTestCase;
15
16
final class RouterConfigTest extends HeaderTestCase
17
{
18
    protected function setUp(): void
19
    {
20
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
21
            $config->resetInMemoryCache();
22
            $config->extendGacelaConfig(RouterGacelaConfig::class);
23
24
            $config->addPlugins([
25
                NameRoutesPlugin::class,
26
                RootRoutesPlugin::class,
27
            ]);
28
        });
29
    }
30
31
    public function test_root_route_plugin(): void
32
    {
33
        $_SERVER['REQUEST_URI'] = 'https://example.org/';
34
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
35
36
        /** @var \Gacela\Router\RouterInterface $gacelaRouter */
37
        $gacelaRouter = Gacela::get(Router::class);
38
        $gacelaRouter->run();
39
40
        $this->expectOutputString((string)json_encode(['hello' => 'bob?']));
41
    }
42
43
    public function test_name_route_plugin(): void
44
    {
45
        $_SERVER['REQUEST_URI'] = 'https://example.org/alice';
46
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
47
48
        /** @var \Gacela\Router\RouterInterface $gacelaRouter */
49
        $gacelaRouter = Gacela::get(Router::class);
50
        $gacelaRouter->run();
51
52
        $this->expectOutputString((string)json_encode(['hello' => 'alice']));
53
    }
54
}
55