From: Brad Jorsch Date: Wed, 14 Feb 2018 18:01:19 +0000 (-0500) Subject: Don't write exceptions to STDERR from BadTitleErrorTest or ThrottledErrorTest X-Git-Tag: 1.31.0-rc.0~586 X-Git-Url: http://git.cyclocoop.org/data/%24oldEdit?a=commitdiff_plain;h=4a275ea53c8bedcabe30396d7ce88a06650568b1;p=lhc%2Fweb%2Fwiklou.git Don't write exceptions to STDERR from BadTitleErrorTest or ThrottledErrorTest It's annoying and pointless. Instead, have MWException write them to standard output where we can catch them with ob_start(). Bug: T170028 Bug: T170029 Change-Id: Icd99c1c39d4a30d78c511d33948ef639e1b92455 --- diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 16f226c78f..b3e9422b8d 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -189,7 +189,7 @@ class MWException extends Exception { } elseif ( self::isCommandLine() ) { $message = $this->getText(); // T17602: STDERR may not be available - if ( defined( 'STDERR' ) ) { + if ( !defined( 'MW_PHPUNIT_TEST' ) && defined( 'STDERR' ) ) { fwrite( STDERR, $message ); } else { echo $message; diff --git a/tests/phpunit/includes/exception/BadTitleErrorTest.php b/tests/phpunit/includes/exception/BadTitleErrorTest.php index dcdb1cd198..b706facedc 100644 --- a/tests/phpunit/includes/exception/BadTitleErrorTest.php +++ b/tests/phpunit/includes/exception/BadTitleErrorTest.php @@ -10,8 +10,10 @@ class BadTitleErrorTest extends MediaWikiTestCase { try { throw new BadTitleError(); } catch ( BadTitleError $e ) { + ob_start(); $e->report(); - $this->assertTrue( true ); + $text = ob_get_clean(); + $this->assertContains( $e->getText(), $text ); } } diff --git a/tests/phpunit/includes/exception/ThrottledErrorTest.php b/tests/phpunit/includes/exception/ThrottledErrorTest.php index 15f08966dc..5214b6d4d1 100644 --- a/tests/phpunit/includes/exception/ThrottledErrorTest.php +++ b/tests/phpunit/includes/exception/ThrottledErrorTest.php @@ -11,8 +11,10 @@ class ThrottledErrorTest extends MediaWikiTestCase { try { throw new ThrottledError(); } catch ( ThrottledError $e ) { + ob_start(); $e->report(); - $this->assertTrue( true ); + $text = ob_get_clean(); + $this->assertContains( $e->getText(), $text ); } }