From f17feae3a991de9f54e0f57d91fe95bf84211fcb Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 31 Jul 2018 16:22:26 +0300 Subject: [PATCH] Reset interwiki table between tests Change-Id: I1c6d5624ffdcc7a624390336d3151e44170916e7 --- tests/phpunit/MediaWikiTestCase.php | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) 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. -- 2.20.1