Merge "Made RepoGroup use ProcessCacheLRU"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index ecc8ad1..7a7ec8f 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
@@ -137,6 +144,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected function getNewTempFile() {
                $fname = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
                $this->tmpfiles[] = $fname;
+
                return $fname;
        }
 
@@ -158,6 +166,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                // where temporary directory creation is bundled and can be improved
                unlink( $fname );
                $this->assertTrue( wfMkdirParents( $fname ) );
+
                return $fname;
        }
 
@@ -170,8 +179,10 @@ 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
+               // @todo global variables to restore for *every* test
                array(
                        'wgLang',
                        'wgContLang',
@@ -231,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__ );
        }
@@ -348,7 +371,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * Stub. If a test needs to add additional data to the database, it should
         * implement this method and do so
         */
-       function addDBData() {}
+       function addDBData() {
+       }
 
        private function addCoreDBData() {
                # disabled for performance
@@ -377,7 +401,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                'page_touched' => $this->db->timestamp(),
                                'page_latest' => 0,
                                'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
-
                }
 
                User::resetIdByNameCache();
@@ -394,7 +417,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $user->saveSettings();
                }
 
-
                //Make 1 page with 1 revision
                $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
                if ( !$page->getId() == 0 ) {
@@ -461,6 +483,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
                        CloneDatabase::changePrefix( $prefix );
+
                        return;
                } else {
                        $dbClone->cloneTableStructure();
@@ -523,6 +546,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
        private static function unprefixTable( $tableName ) {
                global $wgDBprefix;
+
                return substr( $tableName, strlen( $wgDBprefix ) );
        }
 
@@ -534,6 +558,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                global $wgDBprefix;
 
                $tables = $db->listTables( $wgDBprefix, __METHOD__ );
+
+               if ( $db->getType() === 'mysql' ) {
+                       # bug 43571: cannot clone VIEWs under MySQL
+                       $views = $db->listViews( $wgDBprefix, __METHOD__ );
+                       $tables = array_diff( $tables, $views );
+               }
                $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
 
                // Don't duplicate test tables from the previous fataled run
@@ -547,6 +577,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        unset( $tables['searchindex_segments'] );
                        $tables = array_flip( $tables );
                }
+
                return $tables;
        }
 
@@ -561,13 +592,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                if ( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
                        return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
                }
-
        }
 
        public function setCliArg( $offset, $value ) {
 
                MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value;
-
        }
 
        /**
@@ -775,7 +804,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        }
 
        /**
-        * Returns true iff the given namespace defaults to Wikitext
+        * Returns true if the given namespace defaults to Wikitext
         * according to $wgNamespaceContentModels
         *
         * @param int $ns The namespace ID to check
@@ -839,12 +868,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        ) {
 
                                $wikitextNS = $ns;
+
                                return $wikitextNS;
                        }
                }
 
                // give up
-               // @todo: Inside a test, we could skip the test as incomplete.
+               // @todo Inside a test, we could skip the test as incomplete.
                //        But frequently, this is used in fixture setup.
                throw new MWException( "No namespace defaults to wikitext!" );
        }
@@ -906,6 +936,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                if ( !$loaded ) {
                        $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
                }
+
                return $loaded;
        }
 
@@ -914,6 +945,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * the provided code.
         *
         * @since 1.21
+        * @deprecated since 1.22 Use setExpectedException
         *
         * @param callable $code
         * @param string $expected
@@ -934,5 +966,4 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                $this->assertInstanceOf( $expected, $pokemons, $message );
        }
-
 }