/** * @test * @runInSeparateProcess * @depends testPrepareResponse * @param Response $response * @covers ::respond * @uses \AyeAye\Api\Request */ public function testRespond(Response $response) { /** @var Writer|\PHPUnit_Framework_MockObject_MockObject $writer */ $writer = $this->getMockWriter(); $writer->expects($this->exactly(2))->method('getContentType')->with()->will($this->returnValue('')); /** @var Status|\PHPUnit_Framework_MockObject_MockObject $status */ $status = $this->getMockStatus(); $status->expects($this->once())->method('getHttpHeader')->with()->will($this->returnValue(null)); $response->setWriter($writer); ob_start(); $this->assertSame($response, $response->respond()); $this->assertJsonStringEqualsJsonString(json_encode(['data' => 'data']), ob_get_clean()); ob_start(); $response->setStatus($status); $this->assertSame($response, $response->respond()); $this->assertJsonStringEqualsJsonString(json_encode(['data' => 'data']), ob_get_clean()); }
/** * Returns a standardised 500 error. * * To be used in the event of a catastrophic failure, this method creates * all new objects, ignoring dependency injection and returns in JSON. * * This will be problematic for users expecting a response in a format * other than JSON and should only be called if the format they are * actually expecting can not be provided when using * Response::prepareResponse. * * @return Response */ protected function createFailSafeResponse() { $status = new Status(500); $response = new Response(); $response->setRequest(new Request()); $response->setWriter(new Json()); $response->setStatus($status); $response->setBodyData($status->getMessage()); return $response; }