public function before() { $r = new Response(); $r->setResponseCode(500); $r->setBody('_responseFromBefore_'); return $r; }
/** * @runInSeparateProcess */ public function testBodylessResponse() { $response = new Response(); $response->setResponseCode(ResponseCode::HTTP_NO_CONTENT); $response->setBody('test!'); $this->expectOutputString(''); $response->send(); }
/** * Cleans the output buffer and builds a default HTTP 200 OK "Allow" response to an OPTIONS request. */ private function prepareOptionsResponse() { ob_clean(); // Determine which options have been set up for this route based on the registered routes $optionsForRoute = $this->router->getOptions($this->request); $methodsAllowed = [RequestMethod::OPTIONS]; foreach ($optionsForRoute as $route) { // Extend the set of acceptable methods with the ones set up for this route $acceptableMethods = $route->getAcceptableMethods(); $methodsAllowed = array_merge_recursive($methodsAllowed, $acceptableMethods); } array_unique($methodsAllowed); $this->response = new Response(); $this->response->setResponseCode(ResponseCode::HTTP_OK); $this->response->setHeader('Allow', implode(',', $methodsAllowed)); $this->response->setBody(''); $this->context->registerInstance($this->response); $this->finalizeOutputBuffer(); }
/** * @runInSeparateProcess */ public function testSetOverrideResponse() { $request = new Request(); $request->setRequestUri('/bla'); $enlighten = new Enlighten(); $enlighten->setRequest($request); $enlighten->notFound(function (Response $response) use($enlighten) { $responseOverride = new Response(); $responseOverride->setResponseCode(ResponseCode::HTTP_IM_A_TEAPOT); $responseOverride->setBody('i am a teapot'); $enlighten->setResponse($responseOverride); }); $response = $enlighten->start(); $this->assertEquals(ResponseCode::HTTP_IM_A_TEAPOT, $response->getResponseCode()); $this->expectOutputString('i am a teapot'); }