@@ -405,60 +405,31 @@ public function assertEventTriggered(string $eventName): bool
405
405
}
406
406
407
407
/**
408
- * Hooks into xdebug's headers capture, looking for a specific header
409
- * emitted
408
+ * Hooks into xdebug's headers capture, looking for presence of
409
+ * a specific header emitted.
410
410
*
411
411
* @param string $header The leading portion of the header we are looking for
412
- *
413
- * @throws Exception
414
412
*/
415
413
public function assertHeaderEmitted (string $ header , bool $ ignoreCase = false ): void
416
414
{
417
- $ found = false ;
418
-
419
- if (! function_exists ('xdebug_get_headers ' )) {
420
- $ this ->markTestSkipped ('XDebug not found. ' );
421
- }
422
-
423
- foreach (xdebug_get_headers () as $ emitted ) {
424
- $ found = $ ignoreCase ?
425
- (stripos ($ emitted , $ header ) === 0 ) :
426
- (strpos ($ emitted , $ header ) === 0 );
427
- if ($ found ) {
428
- break ;
429
- }
430
- }
431
-
432
- $ this ->assertTrue ($ found , "Didn't find header for {$ header }" );
415
+ $ this ->assertNotNull (
416
+ $ this ->getHeaderEmitted ($ header , $ ignoreCase , __METHOD__ ),
417
+ "Didn't find header for {$ header }"
418
+ );
433
419
}
434
420
435
421
/**
436
- * Hooks into xdebug's headers capture, looking for a specific header
437
- * emitted
422
+ * Hooks into xdebug's headers capture, looking for absence of
423
+ * a specific header emitted.
438
424
*
439
425
* @param string $header The leading portion of the header we don't want to find
440
- *
441
- * @throws Exception
442
426
*/
443
427
public function assertHeaderNotEmitted (string $ header , bool $ ignoreCase = false ): void
444
428
{
445
- $ found = false ;
446
-
447
- if (! function_exists ('xdebug_get_headers ' )) {
448
- $ this ->markTestSkipped ('XDebug not found. ' );
449
- }
450
-
451
- foreach (xdebug_get_headers () as $ emitted ) {
452
- $ found = $ ignoreCase ?
453
- (stripos ($ emitted , $ header ) === 0 ) :
454
- (strpos ($ emitted , $ header ) === 0 );
455
- if ($ found ) {
456
- break ;
457
- }
458
- }
459
-
460
- $ success = ! $ found ;
461
- $ this ->assertTrue ($ success , "Found header for {$ header }" );
429
+ $ this ->assertNull (
430
+ $ this ->getHeaderEmitted ($ header , $ ignoreCase , __METHOD__ ),
431
+ "Found header for {$ header }"
432
+ );
462
433
}
463
434
464
435
/**
@@ -533,23 +504,20 @@ protected function createApplication()
533
504
534
505
/**
535
506
* Return first matching emitted header.
536
- *
537
- * @param string $header Identifier of the header of interest
538
- *
539
- * @return string|null The value of the header found, null if not found
540
507
*/
541
- protected function getHeaderEmitted (string $ header , bool $ ignoreCase = false ): ?string
508
+ protected function getHeaderEmitted (string $ header , bool $ ignoreCase = false , string $ method = __METHOD__ ): ?string
542
509
{
543
510
if (! function_exists ('xdebug_get_headers ' )) {
544
- $ this ->markTestSkipped (' XDebug not found . ' );
511
+ $ this ->markTestSkipped ($ method . ' () requires xdebug . ' );
545
512
}
546
513
547
- foreach (xdebug_get_headers () as $ emitted ) {
548
- $ found = $ ignoreCase ?
549
- (stripos ($ emitted , $ header ) === 0 ) :
550
- (strpos ($ emitted , $ header ) === 0 );
514
+ foreach (xdebug_get_headers () as $ emittedHeader ) {
515
+ $ found = $ ignoreCase
516
+ ? (stripos ($ emittedHeader , $ header ) === 0 )
517
+ : (strpos ($ emittedHeader , $ header ) === 0 );
518
+
551
519
if ($ found ) {
552
- return $ emitted ;
520
+ return $ emittedHeader ;
553
521
}
554
522
}
555
523
0 commit comments