public function testAddingAndFindingRegularRoutes() { foreach (['get', 'post', 'put', 'delete'] as $method) { $fn = function () { }; $this->router->{$method}($method, $method, $fn); $this->assertSame($fn, $this->router->findActionByRoute(HttpMethod::memberByKey($method, false), $method)); } }
/** * Sets all fields on this request object to the globals from PHP * * NOTE: Requests are intended to be immutable - please use this only to construct new requests * * @return void */ protected function createFromGlobals() { if (php_sapi_name() === 'cli') { throw new InvalidStateException('Requests can not be instantiated from globals in CLI mode'); } $method = HttpMethod::memberByKey($_SERVER['REQUEST_METHOD'], false); $uri = strtok($_SERVER['REQUEST_URI'], '?'); $host = $_SERVER['HTTP_HOST']; $headers = getallheaders(); $this->create($method, $uri, $host, $headers, $_COOKIE, $_GET, $_POST); }