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

RouterConfigTest::test_name_route_plugin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 1
b 0
f 0
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