From: Aryeh Gregor Date: Mon, 8 Oct 2018 18:04:12 +0000 (+0300) Subject: Output only to stderr in unit tests X-Git-Tag: 1.34.0-rc.0~3781^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=383a925f682d00d7218a5a36167d4d038a553b13;p=lhc%2Fweb%2Fwiklou.git Output only to stderr in unit tests 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 --- diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index a506dcb377..897919541d 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -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() { diff --git a/tests/phpunit/includes/session/PHPSessionHandlerTest.php b/tests/phpunit/includes/session/PHPSessionHandlerTest.php index b191a2fbf3..94ccd4b572 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -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() ) { diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php index d5a19c287d..65445447f5 100755 --- a/tests/phpunit/phpunit.php +++ b/tests/phpunit/phpunit.php @@ -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 = [];