|
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
|
|
|
|