From b51820a769e522f4358b2f76c741f33e6e77d7a1 Mon Sep 17 00:00:00 2001 From: take64 Date: Tue, 4 May 2021 19:51:17 +0900 Subject: [PATCH] =?UTF-8?q?REQUEST=5FURI=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Router.php | 2 +- tests/RouterTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Router.php b/src/Router.php index b973e3b..55df548 100644 --- a/src/Router.php +++ b/src/Router.php @@ -64,7 +64,7 @@ class Router extends Configurable public function factory(array $request = null): self { // URLがない場合はconfigureのdefaultを取得 - $request['url'] = ($request['url'] ?? $this->configures['default_url']); + $request['url'] = ($request['url'] ?? $_SERVER['REQUEST_URI'] ?? $this->configures['default_url']); // URLをパース $this->parse($request['url']); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 5620f1c..69c08e3 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -68,4 +68,38 @@ public function factory_想定通り() $this->assertSame($router->action, $action); $this->assertSame($router->parameters, $parameters); } + + + + /** + * @test + * @throws ConfigureException + */ + public function factory_想定通りAPI() + { + // 設定値 + $configures = require(dirname(__DIR__) . '/tests/citrus-configure.php'); + + // 生成 + $router = Router::sharedInstance()->loadConfigures($configures); + + // URLパス設計 + $_SERVER['REQUEST_URI'] = '/api/user/login'; + $protocol = 'api'; + $documents = ['user']; + $action = 'login'; + $parameters = ['email' => 'hoge@example.com']; + $request = [ + ]; + $request = array_merge($request, $parameters); + + // アイテムの生成 + $router->factory($request); + + // 検証 + $this->assertSame($router->protocol, $protocol); + $this->assertSame($router->documents, $documents); + $this->assertSame($router->action, $action); + $this->assertSame($router->parameters, $parameters); + } }