MediaWikiTestCase: Fix schema restoration
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 8 Apr 2019 17:48:49 +0000 (13:48 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 8 Apr 2019 17:52:10 +0000 (13:52 -0400)
First, after restoring the old schema it needs to clear the variable so
it doesn't keep "restoring" again and again for every subsequent test
class.

Second, after restoring the old schema it needs to repopulate anything
added by addCoreDBData() that was lost by dropping and recreating the
affected tables, which is easiest done by calling $this->resetDB().

Change-Id: I549d10eb7ceec117d3a0138449ca01f8065707d4

tests/phpunit/MediaWikiTestCase.php

index 8a38f42..f1bb632 100644 (file)
@@ -1616,6 +1616,10 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
 
                if ( $tablesToRestore ) {
                        $this->recloneMockTables( $db, $tablesToRestore );
+
+                       // Reset the restored tables, mainly for the side effect of
+                       // re-calling $this->addCoreDBData() if necessary.
+                       $this->resetDB( $db, $tablesToRestore );
                }
        }
 
@@ -1630,6 +1634,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
 
                if ( $oldOverrides['alter'] || $oldOverrides['create'] || $oldOverrides['drop'] ) {
                        $this->undoSchemaOverrides( $db, $oldOverrides );
+                       unset( $db->_schemaOverrides );
                }
 
                // Determine new overrides.