Improve MediaWikiIntegrationTestCase::resetDB()
authorLucas Werkmeister <lucas.werkmeister@wikimedia.de>
Thu, 12 Sep 2019 15:36:01 +0000 (17:36 +0200)
committerAdam Wight <adam.wight@wikimedia.de>
Fri, 13 Sep 2019 11:01:41 +0000 (13:01 +0200)
Test the intersection of $tablesUsed with each set of tables
separately and only update it afterwards.  Without this fix, overlaps
between the table groups would cause additional groups to be pulled in
unnecessarily.

Change-Id: I1b2a6eb47e061dee8a27fb4779809b4684c05104

tests/phpunit/MediaWikiIntegrationTestCase.php

index b738312..373ea9a 100644 (file)
@@ -1834,9 +1834,11 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        ];
                        $coreDBDataTables = array_merge( $userTables, $pageTables );
 
-                       // If any of the user or page tables were marked as used, we should clear all of them.
+                       // some groups of tables are connected such that if any is used, all should be cleared
+                       $extraTables = [];
                        if ( array_intersect( $tablesUsed, $userTables ) ) {
-                               $tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
+                               $extraTables[] = $userTables;
+
                                TestUserRegistry::clear();
 
                                // Reset $wgUser, which is probably 127.0.0.1, as its loaded data is probably not valid
@@ -1846,7 +1848,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                                $wgUser->clearInstanceCache( $wgUser->mFrom );
                        }
                        if ( array_intersect( $tablesUsed, $pageTables ) ) {
-                               $tablesUsed = array_unique( array_merge( $tablesUsed, $pageTables ) );
+                               $extraTables[] = $pageTables;
+                       }
+                       if ( $extraTables !== [] ) {
+                               $tablesUsed = array_unique( array_merge( $tablesUsed, ...$extraTables ) );
                        }
 
                        // Postgres uses mwuser/pagecontent