Output only to stderr in unit tests
authorAryeh Gregor <ayg@aryeh.name>
Mon, 8 Oct 2018 18:04:12 +0000 (21:04 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 8 Oct 2018 18:04:12 +0000 (21:04 +0300)
Otherwise, session tests don't work in PHP 7.2 because headers are
already sent: https://bugs.php.net/bug.php?id=75628

Bug: T206476
Change-Id: Ie88db4a61a56b756c6445d2579a2f30da22c3ee8

tests/phpunit/MediaWikiPHPUnitCommand.php
tests/phpunit/includes/session/PHPSessionHandlerTest.php
tests/phpunit/phpunit.php

index a506dcb..8979195 100644 (file)
@@ -20,6 +20,9 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
 
                // Add our own listener
                $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener;
+
+               // Output only to stderr to avoid "Headers already sent" problems
+               $this->arguments['stderr'] = true;
        }
 
        protected function createRunner() {
index b191a2f..94ccd4b 100644 (file)
@@ -15,15 +15,6 @@ class PHPSessionHandlerTest extends MediaWikiTestCase {
        private function getResetter( &$rProp = null ) {
                $reset = [];
 
-               // Ignore "headers already sent" warnings during this test
-               set_error_handler( function ( $errno, $errstr ) use ( &$warnings ) {
-                       if ( preg_match( '/[hH]eaders already sent/', $errstr ) ) {
-                               return true;
-                       }
-                       return false;
-               } );
-               $reset[] = new \Wikimedia\ScopedCallback( 'restore_error_handler' );
-
                $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' );
                $rProp->setAccessible( true );
                if ( $rProp->getValue() ) {
index d5a19c2..6544544 100755 (executable)
@@ -58,9 +58,9 @@ class PHPUnitMaintClass extends Maintenance {
                        exit( 1 );
                }
 
-               echo defined( 'HHVM_VERSION' ) ?
+               fwrite( STDERR, defined( 'HHVM_VERSION' ) ?
                        'Using HHVM ' . HHVM_VERSION . ' (' . PHP_VERSION . ")\n" :
-                       'Using PHP ' . PHP_VERSION . "\n";
+                       'Using PHP ' . PHP_VERSION . "\n" );
 
                // Tell PHPUnit to ignore options meant for MediaWiki
                $ignore = [];