From: Aryeh Gregor Date: Tue, 31 Jul 2018 13:22:26 +0000 (+0300) Subject: Reset interwiki table between tests X-Git-Tag: 1.34.0-rc.0~4587^2 X-Git-Url: http://git.cyclocoop.org/%22.%20%20%20generer_url_action%28%22logout%22%2C%22logout=prive%22%29%20.%20%20%20%22?a=commitdiff_plain;h=f17feae3a991de9f54e0f57d91fe95bf84211fcb;p=lhc%2Fweb%2Fwiklou.git Reset interwiki table between tests Change-Id: I1c6d5624ffdcc7a624390336d3151e44170916e7 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index db75bc0b58..0b7481b2a4 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -97,6 +97,12 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { */ private $mwGlobalsToUnset = []; + /** + * Holds original contents of interwiki table + * @var IResultWrapper + */ + private $interwikiTable = null; + /** * Holds original loggers which have been replaced by setLogger() * @var LoggerInterface[] @@ -563,6 +569,12 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { } } + // Store contents of interwiki table in case it changes. Unfortunately, we seem to have no + // way to do this only when needed, because tablesUsed can be changed mid-test. + if ( $this->db ) { + $this->interwikiTable = $this->db->select( 'interwiki', '*', '', __METHOD__ ); + } + // Reset all caches between tests. $this->doLightweightServiceReset(); @@ -1707,11 +1719,6 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { $truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] ); foreach ( $tablesUsed as $tbl ) { - // TODO: reset interwiki table to its original content. - if ( $tbl == 'interwiki' ) { - continue; - } - if ( !$db->tableExists( $tbl ) ) { continue; } @@ -1727,6 +1734,19 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { $db->resetSequenceForTable( $tbl, __METHOD__ ); } + if ( $tbl === 'interwiki' ) { + if ( !$this->interwikiTable ) { + // @todo We should probably throw here, but this causes test failures that I + // can't figure out, so for now we silently continue. + continue; + } + $db->insert( + 'interwiki', + array_map( 'get_object_vars', iterator_to_array( $this->interwikiTable ) ), + __METHOD__ + ); + } + if ( $tbl === 'page' ) { // Forget about the pages since they don't // exist in the DB.