Merge "Fix so wfResetOutputBuffers doesn't break unit tests"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 10 Sep 2015 00:14:21 +0000 (00:14 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 10 Sep 2015 00:14:21 +0000 (00:14 +0000)
includes/GlobalFunctions.php
tests/phpunit/MediaWikiTestCase.php

index 46f7719..a2e1800 100644 (file)
@@ -2194,6 +2194,10 @@ function wfResetOutputBuffers( $resetGzipEncoding = true ) {
                        // output behavior.
                        break;
                }
+               if ( $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier' ) {
+                       // Unit testing barrier to prevent this function from breaking PHPUnit.
+                       break;
+               }
                if ( !ob_end_clean() ) {
                        // Could not remove output buffer handler; abort now
                        // to avoid getting in some kind of infinite loop.
index 43d8ce8..ac214a2 100644 (file)
@@ -208,6 +208,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                DeferredUpdates::clearPendingUpdates();
 
+               ob_start( 'MediaWikiTestCase::wfResetOutputBuffersBarrier' );
        }
 
        protected function addTmpFiles( $files ) {
@@ -215,6 +216,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        }
 
        protected function tearDown() {
+               $status = ob_get_status();
+               if ( isset( $status['name'] ) && $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier' ) {
+                       ob_end_flush();
+               }
+
                $this->called['tearDown'] = true;
                // Cleaning up temporary files
                foreach ( $this->tmpFiles as $fileName ) {
@@ -1174,4 +1180,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                self::assertFalse( self::tagMatch( $matcher, $actual, $isHtml ), $message );
        }
+
+       /**
+        * Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
+        * @return string
+        */
+       public static function wfResetOutputBuffersBarrier( $buffer ) {
+               return $buffer;
+       }
 }