Skip to content

Commit

Permalink
REQUEST_URIに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
take64 committed May 4, 2021
1 parent 1dc4ef2 commit b51820a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
34 changes: 34 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]'];
$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);
}
}

0 comments on commit b51820a

Please sign in to comment.