/** * @runInSeparateProcess * * Unfortunately we have no way of testing if the HTTP response code got * changed. */ function testSend() { if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('XDebug needs to be installed for this test to run'); } $response = new Response(204, ['Content-Type', 'text/xml']); $response->setBody('foo'); ob_start(); Sapi::sendResponse($response); $headers = xdebug_get_headers(); $result = ob_get_clean(); header_remove(); $this->assertEquals(["0: Content-Type", "1: text/xml"], $headers); $this->assertEquals('foo', $result); }
/** * @runInSeparateProcess * * Unfortunately we have no way of testing if the HTTP response code got * changed. */ function testSend() { if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('XDebug needs to be installed for this test to run'); } $response = new Response(204, ['Content-Type' => 'text/xml;charset=UTF-8']); // Second Content-Type header. Normally this doesn't make sense. $response->addHeader('Content-Type', 'application/xml'); $response->setBody('foo'); ob_start(); Sapi::sendResponse($response); $headers = xdebug_get_headers(); $result = ob_get_clean(); header_remove(); $this->assertEquals(["Content-Type: text/xml;charset=UTF-8", "Content-Type: application/xml"], $headers); $this->assertEquals('foo', $result); }
/** * @runInSeparateProcess * @depends testSend */ function testSendLimitedByContentLengthStream() { $response = new Response(200, ['Content-Length' => 19]); $body = fopen('php://memory', 'w'); fwrite($body, 'Ignore this. Send this sentence. Ignore this too.'); rewind($body); fread($body, 13); $response->setBody($body); ob_start(); Sapi::sendResponse($response); $result = ob_get_clean(); header_remove(); $this->assertEquals('Send this sentence.', $result); }