Don’t write to stderr when testing
authorLucas Werkmeister <lucas.werkmeister@wikimedia.de>
Wed, 24 Jan 2018 13:29:23 +0000 (14:29 +0100)
committerLucas Werkmeister <lucas.werkmeister@wikimedia.de>
Wed, 24 Jan 2018 14:05:39 +0000 (15:05 +0100)
This change makes it possible to test error() messages with
expectOutputString() or expectOutputRegex().

Change-Id: I61970403f9c371d3798f34fd48c70bc72f0c7eda

maintenance/Maintenance.php

index 5adbee5..69284ac 100644 (file)
@@ -414,7 +414,10 @@ abstract class Maintenance {
                        $this->fatalError( $err, intval( $die ) );
                }
                $this->outputChanneled( false );
-               if ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) {
+               if (
+                       ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) &&
+                       !defined( 'MW_PHPUNIT_TEST' )
+               ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
                        print $err;