Don't write exceptions to STDERR from BadTitleErrorTest or ThrottledErrorTest
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 14 Feb 2018 18:01:19 +0000 (13:01 -0500)
committerKrinkle <krinklemail@gmail.com>
Fri, 16 Feb 2018 09:01:51 +0000 (09:01 +0000)
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

includes/exception/MWException.php
tests/phpunit/includes/exception/BadTitleErrorTest.php
tests/phpunit/includes/exception/ThrottledErrorTest.php

index 16f226c..b3e9422 100644 (file)
@@ -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;
index dcdb1cd..b706fac 100644 (file)
@@ -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 );
                }
        }
 
index 15f0896..5214b6d 100644 (file)
@@ -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 );
                }
        }