From 08f91482c8d2407c0b4c0d110d97142fa0ce7be6 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 17 Jul 2013 18:42:24 +0200 Subject: [PATCH] Detect leakage of error_reporting state in tests. This causes PHPUnit test cases to fail if they changed the PHP error_reporting settings, and failed to restore it. Change-Id: I34068eac94c974a461af0ff5753d9fcaa375f2e4 --- tests/phpunit/MediaWikiTestCase.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 6ce78b5664..7a7ec8f0c1 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -35,6 +35,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { private static $dbSetup = false; private static $oldTablePrefix = false; + /** + * Original value of PHP's error_reporting setting. + * + * @var int + */ + private $phpErrorLevel; + /** * Holds the paths of temporary files/directories created through getNewTempFile, * and getNewTempDirectory @@ -172,6 +179,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { parent::setUp(); $this->called['setUp'] = 1; + $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) ); + /* // @todo global variables to restore for *every* test array( @@ -233,6 +242,18 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } $this->mwGlobals = array(); + $phpErrorLevel = intval( ini_get( 'error_reporting' ) ); + + if ( $phpErrorLevel !== $this->phpErrorLevel ) { + ini_set( 'error_reporting', $this->phpErrorLevel ); + + $oldHex = strtoupper( dechex( $this->phpErrorLevel ) ); + $newHex = strtoupper( dechex( $phpErrorLevel ) ); + $message = "PHP error_reporting setting was left dirty: was 0x$oldHex before test, 0x$newHex after test!"; + + $this->fail( $message ); + } + parent::tearDown(); wfProfileOut( __METHOD__ ); } -- 2.20.1