Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47dba65

Browse files
authoredApr 7, 2025··
Merge pull request #278 from clue-labs/pcov
Update test suite to use PCOV to avoid segfault with Xdebug 3.4.2
2 parents 417c995 + b441ad6 commit 47dba65

File tree

2 files changed

+112
-70
lines changed

2 files changed

+112
-70
lines changed
 

‎.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- uses: shivammathur/setup-php@v2
2929
with:
3030
php-version: ${{ matrix.php }}
31-
coverage: xdebug
31+
coverage: ${{ matrix.php < 8.0 && 'xdebug' || 'pcov' }}
3232
ini-file: development
3333
- run: composer install
3434
- run: vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml

‎tests/Io/SapiHandlerTest.php

Lines changed: 111 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,11 @@ public function testRequestFromGlobalsWithConnectProxyOverHttps(): void
199199
$this->assertEquals('example.com:443', $request->getHeaderLine('Host'));
200200
}
201201

202+
/**
203+
* @runInSeparateProcess
204+
*/
202205
public function testSendResponseSendsEmptyResponseWithNoHeadersAndEmptyBodyAndAssignsNoContentTypeAndEmptyContentLength(): void
203206
{
204-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
205-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
206-
}
207-
208207
header_remove();
209208
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
210209
$sapi = new SapiHandler();
@@ -213,15 +212,18 @@ public function testSendResponseSendsEmptyResponseWithNoHeadersAndEmptyBodyAndAs
213212
$this->expectOutputString('');
214213
$sapi->sendResponse($response);
215214

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

222+
/**
223+
* @runInSeparateProcess
224+
*/
219225
public function testSendResponseSendsJsonResponseWithGivenHeadersAndBodyAndAssignsMatchingContentLength(): void
220226
{
221-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
222-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
223-
}
224-
225227
header_remove();
226228
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
227229
$sapi = new SapiHandler();
@@ -230,18 +232,18 @@ public function testSendResponseSendsJsonResponseWithGivenHeadersAndBodyAndAssig
230232
$this->expectOutputString('{}');
231233
$sapi->sendResponse($response);
232234

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

236242
/**
237-
* @backupGlobals enabled
243+
* @runInSeparateProcess
238244
*/
239245
public function testSendResponseSendsJsonResponseWithGivenHeadersAndMatchingContentLengthButEmptyBodyForHeadRequest(): void
240246
{
241-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
242-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
243-
}
244-
245247
header_remove();
246248
$_SERVER['REQUEST_METHOD'] = 'HEAD';
247249
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
@@ -251,15 +253,18 @@ public function testSendResponseSendsJsonResponseWithGivenHeadersAndMatchingCont
251253
$this->expectOutputString('');
252254
$sapi->sendResponse($response);
253255

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

263+
/**
264+
* @runInSeparateProcess
265+
*/
257266
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsNoContentLengthForNoContentResponse(): void
258267
{
259-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
260-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
261-
}
262-
263268
header_remove();
264269
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
265270
$sapi = new SapiHandler();
@@ -268,15 +273,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsNoConten
268273
$this->expectOutputString('');
269274
$sapi->sendResponse($response);
270275

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

283+
/**
284+
* @runInSeparateProcess
285+
*/
274286
public function testSendResponseSendsEmptyBodyWithGivenHeadersButWithoutExplicitContentLengthForNoContentResponse(): void
275287
{
276-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
277-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
278-
}
279-
280288
header_remove();
281289
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
282290
$sapi = new SapiHandler();
@@ -285,15 +293,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersButWithoutExplicit
285293
$this->expectOutputString('');
286294
$sapi->sendResponse($response);
287295

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

303+
/**
304+
* @runInSeparateProcess
305+
*/
291306
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsContentLengthForNotModifiedResponse(): void
292307
{
293-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
294-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
295-
}
296-
297308
header_remove();
298309
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
299310
$sapi = new SapiHandler();
@@ -302,15 +313,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndAssignsContentL
302313
$this->expectOutputString('');
303314
$sapi->sendResponse($response);
304315

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

323+
/**
324+
* @runInSeparateProcess
325+
*/
308326
public function testSendResponseSendsEmptyBodyWithGivenHeadersAndExplicitContentLengthForNotModifiedResponse(): void
309327
{
310-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
311-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
312-
}
313-
314328
header_remove();
315329
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
316330
$sapi = new SapiHandler();
@@ -319,15 +333,18 @@ public function testSendResponseSendsEmptyBodyWithGivenHeadersAndExplicitContent
319333
$this->expectOutputString('');
320334
$sapi->sendResponse($response);
321335

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

343+
/**
344+
* @runInSeparateProcess
345+
*/
325346
public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromStreamData(): void
326347
{
327-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
328-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
329-
}
330-
331348
header_remove();
332349
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
333350
$sapi = new SapiHandler();
@@ -337,20 +354,20 @@ public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromSt
337354
$this->expectOutputString('test');
338355
$sapi->sendResponse($response);
339356

340-
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
341-
342357
$body->end('test');
358+
359+
if (!function_exists('xdebug_get_headers')) {
360+
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
361+
return;
362+
}
363+
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
343364
}
344365

345366
/**
346-
* @backupGlobals enabled
367+
* @runInSeparateProcess
347368
*/
348369
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForHeadRequest(): void
349370
{
350-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
351-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
352-
}
353-
354371
header_remove();
355372
$_SERVER['REQUEST_METHOD'] = 'HEAD';
356373
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
@@ -361,16 +378,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
361378
$this->expectOutputString('');
362379
$sapi->sendResponse($response);
363380

364-
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
365381
$this->assertFalse($body->isReadable());
382+
383+
if (!function_exists('xdebug_get_headers')) {
384+
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
385+
return;
386+
}
387+
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
366388
}
367389

390+
/**
391+
* @runInSeparateProcess
392+
*/
368393
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForNotModifiedResponse(): void
369394
{
370-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
371-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
372-
}
373-
374395
header_remove();
375396
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
376397
$sapi = new SapiHandler();
@@ -380,16 +401,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
380401
$this->expectOutputString('');
381402
$sapi->sendResponse($response);
382403

383-
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
384404
$this->assertFalse($body->isReadable());
405+
406+
if (!function_exists('xdebug_get_headers')) {
407+
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
408+
return;
409+
}
410+
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
385411
}
386412

413+
/**
414+
* @runInSeparateProcess
415+
*/
387416
public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHeadersAndBodyForNoContentResponse(): void
388417
{
389-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
390-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
391-
}
392-
393418
header_remove();
394419
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
395420
$sapi = new SapiHandler();
@@ -399,16 +424,20 @@ public function testSendResponseClosesStreamingResponseAndSendsResponseWithNoHea
399424
$this->expectOutputString('');
400425
$sapi->sendResponse($response);
401426

402-
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
403427
$this->assertFalse($body->isReadable());
428+
429+
if (!function_exists('xdebug_get_headers')) {
430+
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
431+
return;
432+
}
433+
$this->assertEquals(['Content-Type:'], xdebug_get_headers());
404434
}
405435

436+
/**
437+
* @runInSeparateProcess
438+
*/
406439
public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromStreamDataAndNoBufferHeaderForNginxServer(): void
407440
{
408-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
409-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
410-
}
411-
412441
header_remove();
413442
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
414443
$_SERVER['SERVER_SOFTWARE'] = 'nginx/1';
@@ -419,17 +448,20 @@ public function testSendResponseSendsStreamingResponseWithNoHeadersAndBodyFromSt
419448
$this->expectOutputString('test');
420449
$sapi->sendResponse($response);
421450

422-
$this->assertEquals(['Content-Type:', 'X-Accel-Buffering: no'], xdebug_get_headers());
423-
424451
$body->end('test');
452+
453+
if (!function_exists('xdebug_get_headers')) {
454+
// $this->markTestIncomplete('Testing headers requires running PHPUnit with Xdebug enabled');
455+
return;
456+
}
457+
$this->assertEquals(['Content-Type:', 'X-Accel-Buffering: no'], xdebug_get_headers());
425458
}
426459

460+
/**
461+
* @runInSeparateProcess
462+
*/
427463
public function testSendResponseSetsMultipleCookieHeaders(): void
428464
{
429-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
430-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
431-
}
432-
433465
header_remove();
434466
$_SERVER['SERVER_PROTOCOL'] = 'http/1.1';
435467
$sapi = new SapiHandler();
@@ -438,15 +470,18 @@ public function testSendResponseSetsMultipleCookieHeaders(): void
438470
$this->expectOutputString('');
439471
$sapi->sendResponse($response);
440472

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

480+
/**
481+
* @runInSeparateProcess
482+
*/
444483
public function testRunWillSendResponseHeadersFromHandler(): void
445484
{
446-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
447-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
448-
}
449-
450485
$sapi = new SapiHandler();
451486

452487
header_remove();
@@ -457,15 +492,18 @@ public function testRunWillSendResponseHeadersFromHandler(): void
457492
return new Response();
458493
});
459494

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

502+
/**
503+
* @runInSeparateProcess
504+
*/
463505
public function testRunWillSendResponseHeadersFromDeferredHandler(): void
464506
{
465-
if (headers_sent() || !function_exists('xdebug_get_headers')) {
466-
$this->markTestSkipped('Test requires running PHPUnit with Xdebug enabled');
467-
}
468-
469507
$sapi = new SapiHandler();
470508

471509
header_remove();
@@ -476,6 +514,10 @@ public function testRunWillSendResponseHeadersFromDeferredHandler(): void
476514
return resolve(new Response());
477515
});
478516

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

0 commit comments

Comments
 (0)
Please sign in to comment.