Merge "Mechanism for renaming/aliasing classes"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 6ce78b5..9ebca3f 100644 (file)
@@ -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
@@ -46,7 +53,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        /**
         * Holds original values of MediaWiki configuration settings
         * to be restored in tearDown().
-        * See also setMwGlobal().
+        * See also setMwGlobals().
         * @var array
         */
        private $mwGlobals = array();
@@ -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__ );
        }