From: Brad Jorsch Date: Fri, 21 Aug 2015 16:01:10 +0000 (-0400) Subject: Fix so wfResetOutputBuffers doesn't break unit tests X-Git-Tag: 1.31.0-rc.0~10071^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=437936215422d8d8bb3b7db0fb101d9dba78cb1d;p=lhc%2Fweb%2Fwiklou.git Fix so wfResetOutputBuffers doesn't break unit tests If something being unit tested calls wfResetOutputBuffers(), it'll break PHPUnit's attempt to capture output in order to fail tests. In the old version we're currently using for Jenkins it will throw a warning "ob_end_clean(): failed to delete buffer. No buffer to delete", while in newer versions it'll detect that its buffer was removed and fail the test as risky instead. The solution here is to have MediaWikiTestCase add a buffer with a known name in setUp() (and remove it in tearDown()), and have wfResetOutputBuffers() stop when it sees that known name on the stack. Bug: T109843 Change-Id: I8acd91ec9dd9c6d78a5d91d96202249f571d5d83 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e158e5cc40..1a3ecc76ce 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2193,6 +2193,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. diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 43d8ce8691..ac214a29ef 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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; + } }