Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
coverage: ${{ matrix.php < 8.0 && 'xdebug' || 'pcov' }}
ini-file: development
- run: composer install
- run: vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml
Expand Down
180 changes: 111 additions & 69 deletions tests/Io/SapiHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,11 @@ public function testRequestFromGlobalsWithConnectProxyOverHttps(): void
$this->assertEquals('example.com:443', $request->getHeaderLine('Host'));
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsEmptyResponseWithNoHeadersAndEmptyBodyAndAssignsNoContentTypeAndEmptyContentLength(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -213,15 +212,18 @@ public function testSendResponseSendsEmptyResponseWithNoHeadersAndEmptyBodyAndAs
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:', 'Content-Length: 0'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsJsonResponseWithGivenHeadersAndBodyAndAssignsMatchingContentLength(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -230,18 +232,18 @@ public function testSendResponseSendsJsonResponseWithGivenHeadersAndBodyAndAssig
$this->expectOutputString('{}');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json', 'Content-Length: 2'], xdebug_get_headers());
}

/**
* @backupGlobals enabled
* @runInSeparateProcess
*/
public function testSendResponseSendsJsonResponseWithGivenHeadersAndMatchingContentLengthButEmptyBodyForHeadRequest(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['REQUEST_METHOD'] = 'HEAD';
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
Expand All @@ -251,15 +253,18 @@ public function testSendResponseSendsJsonResponseWithGivenHeadersAndMatchingCont
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json', 'Content-Length: 2'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsNoContentLengthForNoContentResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -268,15 +273,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsNoConten
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsEmptyBodyWithGivenHeadersButWithoutExplicitContentLengthForNoContentResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -285,15 +293,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersButWithoutExplicit
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsContentLengthForNotModifiedResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -302,15 +313,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsContentL
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json', 'Content-Length: 4'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndExplicitContentLengthForNotModifiedResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -319,15 +333,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndExplicitContent
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type: application/json', 'Content-Length: 2'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromStreamData(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -337,20 +354,20 @@ public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromSt
$this->expectOutputString('test');
$sapi->sendResponse($response);

$this->assertEquals(['Content-Type:'], xdebug_get_headers());

$body->end('test');

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
}

/**
* @backupGlobals enabled
* @runInSeparateProcess
*/
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForHeadRequest(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['REQUEST_METHOD'] = 'HEAD';
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
Expand All @@ -361,16 +378,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
$this->expectOutputString('');
$sapi->sendResponse($response);

$this->assertEquals(['Content-Type:'], xdebug_get_headers());
$this->assertFalse($body->isReadable());

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForNotModifiedResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -380,16 +401,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
$this->expectOutputString('');
$sapi->sendResponse($response);

$this->assertEquals(['Content-Type:'], xdebug_get_headers());
$this->assertFalse($body->isReadable());

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForNoContentResponse(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -399,16 +424,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
$this->expectOutputString('');
$sapi->sendResponse($response);

$this->assertEquals(['Content-Type:'], xdebug_get_headers());
$this->assertFalse($body->isReadable());

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromStreamDataAndNoBufferHeaderForNginxServer(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$_SERVER['SERVER_SOFTWARE'] = 'nginx/1';
Expand All @@ -419,17 +448,20 @@ public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromSt
$this->expectOutputString('test');
$sapi->sendResponse($response);

$this->assertEquals(['Content-Type:', 'X-Accel-Buffering: no'], xdebug_get_headers());

$body->end('test');

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:', 'X-Accel-Buffering: no'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testSendResponseSetsMultipleCookieHeaders(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

header_remove();
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
$sapi = new SapiHandler();
Expand All @@ -438,15 +470,18 @@ public function testSendResponseSetsMultipleCookieHeaders(): void
$this->expectOutputString('');
$sapi->sendResponse($response);

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:', 'Set-Cookie: 1=1', 'Set-Cookie: 2=2'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testRunWillSendResponseHeadersFromHandler(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

$sapi = new SapiHandler();

header_remove();
Expand All @@ -457,15 +492,18 @@ public function testRunWillSendResponseHeadersFromHandler(): void
return new Response();
});

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:', 'Content-Length: 0'], xdebug_get_headers());
}

/**
* @runInSeparateProcess
*/
public function testRunWillSendResponseHeadersFromDeferredHandler(): void
{
if (headers_sent() || !function_exists('xdebug_get_headers')) {
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
}

$sapi = new SapiHandler();

header_remove();
Expand All @@ -476,6 +514,10 @@ public function testRunWillSendResponseHeadersFromDeferredHandler(): void
return resolve(new Response());
});

if (!function_exists('xdebug_get_headers')) {
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
return;
}
$this->assertEquals(['Content-Type:', 'Content-Length: 0'], xdebug_get_headers());
}
}