Merge "WebStart: Remove use of realpath() for $IP"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 156de4c..4d3c37b 100644 (file)
@@ -213,6 +213,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         *
         * @param Config|null $bootstrapConfig The bootstrap config to use with the new
         *        MediaWikiServices.
+        * @return MediaWikiServices
         */
        protected static function resetGlobalServices( Config $bootstrapConfig = null ) {
                $oldServices = MediaWikiServices::getInstance();
@@ -300,7 +301,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        'ConfigFactory',
                        self::makeTestConfigFactoryInstantiator(
                                $oldConfigFactory,
-                               [ 'main' =>  $bootstrapConfig ]
+                               [ 'main' => $bootstrapConfig ]
                        )
                );
                $newServices->resetServiceForTesting( 'DBLoadBalancerFactory' );
@@ -967,12 +968,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * @since 1.18
         */
        public function needsDB() {
-               # if the test says it uses database tables, it needs the database
+               // If the test says it uses database tables, it needs the database
                if ( $this->tablesUsed ) {
                        return true;
                }
 
-               # if the test says it belongs to the Database group, it needs the database
+               // If the test class says it belongs to the Database group, it needs the database.
+               // NOTE: This ONLY checks for the group in the class level doc comment.
                $rc = new ReflectionClass( $this );
                if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
                        return true;
@@ -1254,7 +1256,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         *
         * @return Database[] Array of Database master connections
         */
-
        protected static function getExternalStoreDatabaseConnections() {
                global $wgDefaultExternalStore;
 
@@ -1304,13 +1305,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        private function resetDB( $db, $tablesUsed ) {
                if ( $db ) {
                        $userTables = [ 'user', 'user_groups', 'user_properties' ];
-                       $coreDBDataTables = array_merge( $userTables, [ 'page', 'revision' ] );
+                       $pageTables = [ 'page', 'revision', 'ip_changes', 'revision_comment_temp', 'comment' ];
+                       $coreDBDataTables = array_merge( $userTables, $pageTables );
 
-                       // If any of the user tables were marked as used, we should clear all of them.
+                       // If any of the user or page tables were marked as used, we should clear all of them.
                        if ( array_intersect( $tablesUsed, $userTables ) ) {
                                $tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
                                TestUserRegistry::clear();
                        }
+                       if ( array_intersect( $tablesUsed, $pageTables ) ) {
+                               $tablesUsed = array_unique( array_merge( $tablesUsed, $pageTables ) );
+                       }
 
                        $truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] );
                        foreach ( $tablesUsed as $tbl ) {
@@ -1490,7 +1495,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                ' method should return true. Use @group Database or $this->tablesUsed.' );
                }
 
-               $db = wfGetDB( DB_SLAVE );
+               $db = wfGetDB( DB_REPLICA );
 
                $res = $db->select( $table, $fields, $condition, wfGetCaller(), [ 'ORDER BY' => $fields ] );
                $this->assertNotEmpty( $res, "query failed: " . $db->lastError() );
@@ -1588,7 +1593,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         *
         * @since 1.20
         *
-        * @param array $array
+        * @param array &$array
         */
        protected function objectAssociativeSort( array &$array ) {
                uasort(
@@ -1606,7 +1611,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         *
         * @since 1.20
         *
-        * @param mixed $r The array to remove string keys from.
+        * @param mixed &$r The array to remove string keys from.
         */
        protected static function stripStringKeys( &$r ) {
                if ( !is_array( $r ) ) {
@@ -1829,6 +1834,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
        /**
         * Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
+        * @param string $buffer
         * @return string
         */
        public static function wfResetOutputBuffersBarrier( $buffer ) {