/** * Makes a request via the framework. * * @param string $method * @param string $uri * @param array $headers * @param array $get * @param array $post * @param string $content * @return \Wilson\Http\Response */ protected function call($method, $uri, $headers = array(), $get = array(), $post = array(), $content = "") { $server = array_merge($headers, array("REQUEST_METHOD" => $method, "REQUEST_URI" => $uri)); $response = new Response(); $request = new Request(); $request->mock($server, $get, $post, array(), array(), $content); $this->_api->dispatch($request, $response); return $response; }
function testSendCookies() { $cookie = new Cookie("name", "value"); $this->response->addCookie($cookie); $this->request->mock(); $this->send(); $expected = array("HTTP/1.1 200 OK", "Date: " . $this->response->getHeader("Date"), "Content-Length: 0", "Set-Cookie: " . $cookie); $this->assertEquals($expected, HeaderStack::stack()); }
/** * Dispatches the request and, if the Api is not under test, sends the * response back to the User Agent. * * @param Request $request * @param Response $response * @return void */ public function dispatch(Request $request = null, Response $response = null) { if (!$request) { $request = new Request(); $request->initialise($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES, file_get_contents("php://input")); } if (!$response) { $response = new Response(); } $this->services->initialise($request, $response); $router = new Router(new Cache($this->cacheFile), new UrlTools()); $dispatcher = new Dispatcher($this, $request, $response, $router, new Sender($request, $response)); $dispatcher->dispatch(); }
/** * Test parses query string * * Pre-conditions: * $_SERVER['QUERY_STRING'] does not exist; */ public function testParsesQueryStringThatDoesNotExist() { $req = new Request(); $req->mock(); $this->assertEquals("", $req->getQueryString()); }
function testMethodNotAllowedDispatch() { $this->request->mock(array("REQUEST_URI" => "/route-1", "REQUEST_METHOD" => "POST")); $this->assertEmpty($this->dispatch()); $this->assertEquals(405, $this->response->getStatus()); }
/** * Responds to the client to confirm method not allowed. * * @param \stdClass $match * @return void */ protected function routeToNotAllowed($match) { $status = $this->request->getMethod() === "OPTIONS" ? 200 : 405; $this->response->setHeader("Allow", join(", ", $match->allowed)); $this->response->setStatus($status); }
function middleware(Request $request) { $request->setParam("middleware_called", true); }