aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/Category/CategoryTest.php12
-rw-r--r--tests/phpunit/includes/Revision/ArchivedRevisionLookupTest.php3
-rw-r--r--tests/phpunit/includes/Revision/RevisionStoreDbTest.php30
-rw-r--r--tests/phpunit/includes/api/ApiBlockTest.php9
-rw-r--r--tests/phpunit/includes/api/ApiChangeContentModelTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiComparePagesTest.php4
-rw-r--r--tests/phpunit/includes/api/ApiDeleteTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiLoginTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiParseTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiStashEditTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiUnblockTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiUserrightsTest.php3
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryBlockInfoTraitTest.php5
-rw-r--r--tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php11
-rw-r--r--tests/phpunit/includes/auth/AuthManagerTest.php6
-rw-r--r--tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php9
-rw-r--r--tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php8
-rw-r--r--tests/phpunit/includes/block/BlockRestrictionStoreTest.php12
-rw-r--r--tests/phpunit/includes/changetags/ChangeTagsTest.php4
-rw-r--r--tests/phpunit/includes/db/LBFactoryTest.php8
-rw-r--r--tests/phpunit/includes/deferred/LinksUpdateTest.php5
-rw-r--r--tests/phpunit/includes/deferred/RefreshSecondaryDataUpdateTest.php4
-rw-r--r--tests/phpunit/includes/deferred/SiteStatsUpdateTest.php2
-rw-r--r--tests/phpunit/includes/editpage/EditPageConstraintsTest.php4
-rw-r--r--tests/phpunit/includes/editpage/EditPageTest.php10
-rw-r--r--tests/phpunit/includes/filerepo/file/LocalFileTest.php6
-rw-r--r--tests/phpunit/includes/import/ImportTest.php2
-rw-r--r--tests/phpunit/includes/interwiki/InterwikiTest.php2
-rw-r--r--tests/phpunit/includes/language/MessageCacheTest.php6
-rw-r--r--tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php6
-rw-r--r--tests/phpunit/includes/page/PageArchiveTest.php2
-rw-r--r--tests/phpunit/includes/page/WikiPageDbTest.php14
-rw-r--r--tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php5
-rw-r--r--tests/phpunit/includes/session/BotPasswordSessionProviderTest.php2
-rw-r--r--tests/phpunit/includes/user/BotPasswordTest.php4
-rw-r--r--tests/phpunit/includes/user/UserTest.php2
36 files changed, 95 insertions, 123 deletions
diff --git a/tests/phpunit/includes/Category/CategoryTest.php b/tests/phpunit/includes/Category/CategoryTest.php
index 479b98ebebda..9b37875455d9 100644
--- a/tests/phpunit/includes/Category/CategoryTest.php
+++ b/tests/phpunit/includes/Category/CategoryTest.php
@@ -103,9 +103,7 @@ class CategoryTest extends MediaWikiIntegrationTestCase {
}
public function testNewFromRow_found() {
- $dbw = wfGetDB( DB_PRIMARY );
-
- $category = Category::newFromRow( $dbw->newSelectQueryBuilder()
+ $category = Category::newFromRow( $this->getDb()->newSelectQueryBuilder()
->select( [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ] )
->from( 'category' )
->where( [ 'cat_id' => 1 ] )
@@ -116,9 +114,7 @@ class CategoryTest extends MediaWikiIntegrationTestCase {
}
public function testNewFromRow_notFoundWithoutTitle() {
- $dbw = wfGetDB( DB_PRIMARY );
-
- $row = $dbw->newSelectQueryBuilder()
+ $row = $this->getDb()->newSelectQueryBuilder()
->select( [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ] )
->from( 'category' )
->where( [ 'cat_id' => 1 ] )
@@ -129,9 +125,7 @@ class CategoryTest extends MediaWikiIntegrationTestCase {
}
public function testNewFromRow_notFoundWithTitle() {
- $dbw = wfGetDB( DB_PRIMARY );
-
- $row = $dbw->newSelectQueryBuilder()
+ $row = $this->getDb()->newSelectQueryBuilder()
->select( [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ] )
->from( 'category' )
->where( [ 'cat_id' => 1 ] )
diff --git a/tests/phpunit/includes/Revision/ArchivedRevisionLookupTest.php b/tests/phpunit/includes/Revision/ArchivedRevisionLookupTest.php
index 7f90a899b682..4034b607f0fe 100644
--- a/tests/phpunit/includes/Revision/ArchivedRevisionLookupTest.php
+++ b/tests/phpunit/includes/Revision/ArchivedRevisionLookupTest.php
@@ -104,8 +104,7 @@ class ArchivedRevisionLookupTest extends MediaWikiIntegrationTestCase {
$rev->setContent( SlotRecord::MAIN, $newContent );
$rev->setComment( CommentStoreComment::newUnsavedComment( 'just a test' ) );
- $dbw = wfGetDB( DB_PRIMARY );
- $this->secondRev = $revisionStore->insertRevisionOn( $rev, $dbw );
+ $this->secondRev = $revisionStore->insertRevisionOn( $rev, $this->getDb() );
// Delete the page
$timestamp += 10;
diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
index 5de038fbcdbb..68445cb587ca 100644
--- a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
+++ b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
@@ -410,7 +410,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
$store = $this->getServiceContainer()->getRevisionStore();
- $return = $store->insertRevisionOn( $rev, wfGetDB( DB_PRIMARY ) );
+ $return = $store->insertRevisionOn( $rev, $this->getDb() );
// is the new revision correct?
$this->assertRevisionCompleteness( $return );
@@ -511,14 +511,14 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
// Insert the first revision
$revOne = $this->getRevisionRecordFromDetailsArray( $revDetails );
- $firstReturn = $store->insertRevisionOn( $revOne, wfGetDB( DB_PRIMARY ) );
+ $firstReturn = $store->insertRevisionOn( $revOne, $this->getDb() );
$this->assertLinkTargetsEqual( $title, $firstReturn->getPageAsLinkTarget() );
$this->assertRevisionRecordsEqual( $revOne, $firstReturn );
// Insert a second revision inheriting the same blob address
$revDetails['slot'] = SlotRecord::newInherited( $firstReturn->getSlot( SlotRecord::MAIN ) );
$revTwo = $this->getRevisionRecordFromDetailsArray( $revDetails );
- $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_PRIMARY ) );
+ $secondReturn = $store->insertRevisionOn( $revTwo, $this->getDb() );
$this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
$this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
@@ -614,7 +614,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$this->expectException( get_class( $exception ) );
$this->expectExceptionMessage( $exception->getMessage() );
$this->expectExceptionCode( $exception->getCode() );
- $store->insertRevisionOn( $rev, wfGetDB( DB_PRIMARY ) );
+ $store->insertRevisionOn( $rev, $this->getDb() );
}
public static function provideNewNullRevision() {
@@ -667,12 +667,12 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$baseRev = $this->getRevisionRecordFromDetailsArray( $revDetails );
$store = $this->getServiceContainer()->getRevisionStore();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$baseRev = $store->insertRevisionOn( $baseRev, $dbw );
$page->updateRevisionOn( $dbw, $baseRev, $page->getLatest() );
$record = $store->newNullRevision(
- wfGetDB( DB_PRIMARY ),
+ $this->getDb(),
$title,
$comment,
$minor,
@@ -707,7 +707,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
public function testNewNullRevision_nonExistingTitle() {
$store = $this->getServiceContainer()->getRevisionStore();
$record = $store->newNullRevision(
- wfGetDB( DB_PRIMARY ),
+ $this->getDb(),
Title::newFromText( __METHOD__ . '.iDontExist!' ),
CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment' ),
false,
@@ -1894,17 +1894,17 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$this->assertSame(
0,
- $store->countRevisionsByPageId( wfGetDB( DB_PRIMARY ), $page->getId() )
+ $store->countRevisionsByPageId( $this->getDb(), $page->getId() )
);
$page->doUserEditContent( new WikitextContent( 'a' ), $user, 'a' );
$this->assertSame(
1,
- $store->countRevisionsByPageId( wfGetDB( DB_PRIMARY ), $page->getId() )
+ $store->countRevisionsByPageId( $this->getDb(), $page->getId() )
);
$page->doUserEditContent( new WikitextContent( 'b' ), $user, 'b' );
$this->assertSame(
2,
- $store->countRevisionsByPageId( wfGetDB( DB_PRIMARY ), $page->getId() )
+ $store->countRevisionsByPageId( $this->getDb(), $page->getId() )
);
}
@@ -1918,17 +1918,17 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$this->assertSame(
0,
- $store->countRevisionsByTitle( wfGetDB( DB_PRIMARY ), $page->getTitle() )
+ $store->countRevisionsByTitle( $this->getDb(), $page->getTitle() )
);
$page->doUserEditContent( new WikitextContent( 'a' ), $user, 'a' );
$this->assertSame(
1,
- $store->countRevisionsByTitle( wfGetDB( DB_PRIMARY ), $page->getTitle() )
+ $store->countRevisionsByTitle( $this->getDb(), $page->getTitle() )
);
$page->doUserEditContent( new WikitextContent( 'b' ), $user, 'b' );
$this->assertSame(
2,
- $store->countRevisionsByTitle( wfGetDB( DB_PRIMARY ), $page->getTitle() )
+ $store->countRevisionsByTitle( $this->getDb(), $page->getTitle() )
);
}
@@ -1946,7 +1946,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$store = $this->getServiceContainer()->getRevisionStore();
$result = $store->userWasLastToEdit(
- wfGetDB( DB_PRIMARY ),
+ $this->getDb(),
$page->getId(),
$sysop->getId(),
'20160101010101'
@@ -1969,7 +1969,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$store = $this->getServiceContainer()->getRevisionStore();
$result = $store->userWasLastToEdit(
- wfGetDB( DB_PRIMARY ),
+ $this->getDb(),
$page->getId(),
$sysop->getId(),
$startTime
diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php
index aebc1d3f0929..d1508c01dd0b 100644
--- a/tests/phpunit/includes/api/ApiBlockTest.php
+++ b/tests/phpunit/includes/api/ApiBlockTest.php
@@ -122,8 +122,7 @@ class ApiBlockTest extends ApiTestCase {
$this->doBlock( [ 'tags' => 'custom tag' ] );
- $dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 1, (int)$dbw->newSelectQueryBuilder()
+ $this->assertSame( 1, (int)$this->getDb()->newSelectQueryBuilder()
->select( 'COUNT(*)' )
->from( 'logging' )
->join( 'change_tag', null, 'ct_log_id = log_id' )
@@ -176,8 +175,7 @@ class ApiBlockTest extends ApiTestCase {
$res = $this->doBlock( [ 'noemail' => '' ] );
- $dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( '1', $dbw->newSelectQueryBuilder()
+ $this->assertSame( '1', $this->getDb()->newSelectQueryBuilder()
->select( 'ipb_block_email' )
->from( 'ipblocks' )
->where( [ 'ipb_id' => $res[0]['block']['id'] ] )
@@ -200,8 +198,7 @@ class ApiBlockTest extends ApiTestCase {
MWTimestamp::setFakeTime( $fakeTime );
$res = $this->doBlock( [ 'expiry' => '1 day' ] );
- $dbw = wfGetDB( DB_PRIMARY );
- $expiry = $dbw->newSelectQueryBuilder()
+ $expiry = $this->getDb()->newSelectQueryBuilder()
->select( 'ipb_expiry' )
->from( 'ipblocks' )
->where( [ 'ipb_id' => $res[0]['block']['id'] ] )
diff --git a/tests/phpunit/includes/api/ApiChangeContentModelTest.php b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
index 7ba861ab6bec..e074a84396b4 100644
--- a/tests/phpunit/includes/api/ApiChangeContentModelTest.php
+++ b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
@@ -321,10 +321,9 @@ class ApiChangeContentModelTest extends ApiTestCase {
'Second revision should come after the first'
);
- $dbw = wfGetDB( DB_PRIMARY );
$this->assertSame(
'4',
- $dbw->newSelectQueryBuilder()
+ $this->getDb()->newSelectQueryBuilder()
->select( 'ctd_count' )
->from( 'change_tag_def' )
->where( [ 'ctd_name' => 'api edit content model tag' ] )
diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php
index 26b6a4150db2..36e9f12867e7 100644
--- a/tests/phpunit/includes/api/ApiComparePagesTest.php
+++ b/tests/phpunit/includes/api/ApiComparePagesTest.php
@@ -73,14 +73,14 @@ class ApiComparePagesTest extends ApiTestCase {
$id = $this->addPage( 'D', 'D 1' );
self::$repl['pageD'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest D' )->getArticleID();
- wfGetDB( DB_PRIMARY )->delete( 'revision', [ 'rev_id' => $id ] );
+ $this->getDb()->delete( 'revision', [ 'rev_id' => $id ] );
self::$repl['revE1'] = $this->addPage( 'E', 'E 1' );
self::$repl['revE2'] = $this->addPage( 'E', 'E 2' );
self::$repl['revE3'] = $this->addPage( 'E', 'E 3' );
self::$repl['revE4'] = $this->addPage( 'E', 'E 4' );
self::$repl['pageE'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest E' )->getArticleID();
- wfGetDB( DB_PRIMARY )->update(
+ $this->getDb()->update(
'page', [ 'page_latest' => 0 ], [ 'page_id' => self::$repl['pageE'] ]
);
diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php b/tests/phpunit/includes/api/ApiDeleteTest.php
index 497c49ea376f..e3a3364035cd 100644
--- a/tests/phpunit/includes/api/ApiDeleteTest.php
+++ b/tests/phpunit/includes/api/ApiDeleteTest.php
@@ -148,8 +148,7 @@ class ApiDeleteTest extends ApiTestCase {
$this->assertFalse( $title->exists( Title::READ_LATEST ) );
- $dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 'custom tag', $dbw->newSelectQueryBuilder()
+ $this->assertSame( 'custom tag', $this->getDb()->newSelectQueryBuilder()
->select( 'ctd_name' )
->from( 'logging' )
->join( 'change_tag', null, 'ct_log_id = log_id' )
diff --git a/tests/phpunit/includes/api/ApiLoginTest.php b/tests/phpunit/includes/api/ApiLoginTest.php
index 411c1932d4e1..d107da3fbc6a 100644
--- a/tests/phpunit/includes/api/ApiLoginTest.php
+++ b/tests/phpunit/includes/api/ApiLoginTest.php
@@ -315,8 +315,7 @@ class ApiLoginTest extends ApiTestCase {
// A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
$passwordHash = $passwordFactory->newFromPlaintext( $password );
- $dbw = wfGetDB( DB_PRIMARY );
- $dbw->insert(
+ $this->getDb()->insert(
'bot_passwords',
[
'bp_user' => $centralId,
diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php
index 09f0c9de386b..0df966d8cc28 100644
--- a/tests/phpunit/includes/api/ApiParseTest.php
+++ b/tests/phpunit/includes/api/ApiParseTest.php
@@ -135,8 +135,7 @@ class ApiParseTest extends ApiTestCase {
* Set up an interwiki entry for testing.
*/
protected function setupInterwiki() {
- $dbw = wfGetDB( DB_PRIMARY );
- $dbw->insert(
+ $this->getDb()->insert(
'interwiki',
[
'iw_prefix' => 'madeuplanguage',
diff --git a/tests/phpunit/includes/api/ApiStashEditTest.php b/tests/phpunit/includes/api/ApiStashEditTest.php
index 1130ee4742fd..dfd413c31cf4 100644
--- a/tests/phpunit/includes/api/ApiStashEditTest.php
+++ b/tests/phpunit/includes/api/ApiStashEditTest.php
@@ -197,8 +197,7 @@ class ApiStashEditTest extends ApiTestCase {
$this->expectApiErrorCode( 'missingrev' );
// Corrupt the database. @todo Does the API really need to fail gracefully for this case?
- $dbw = wfGetDB( DB_PRIMARY );
- $dbw->newUpdateQueryBuilder()
+ $this->getDb()->newUpdateQueryBuilder()
->update( 'page' )
->set( [ 'page_latest' => 0 ] )
->where( [ 'page_id' => $revRecord->getPageId() ] )
diff --git a/tests/phpunit/includes/api/ApiUnblockTest.php b/tests/phpunit/includes/api/ApiUnblockTest.php
index ffec687600a7..923d7d89aec6 100644
--- a/tests/phpunit/includes/api/ApiUnblockTest.php
+++ b/tests/phpunit/includes/api/ApiUnblockTest.php
@@ -122,8 +122,7 @@ class ApiUnblockTest extends ApiTestCase {
$this->doUnblock( [ 'tags' => 'custom tag' ] );
- $dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 1, (int)$dbw->newSelectQueryBuilder()
+ $this->assertSame( 1, (int)$this->getDb()->newSelectQueryBuilder()
->select( 'COUNT(*)' )
->from( 'logging' )
->join( 'change_tag', null, 'ct_log_id = log_id' )
diff --git a/tests/phpunit/includes/api/ApiUserrightsTest.php b/tests/phpunit/includes/api/ApiUserrightsTest.php
index bef4019705f1..6609f21a150a 100644
--- a/tests/phpunit/includes/api/ApiUserrightsTest.php
+++ b/tests/phpunit/includes/api/ApiUserrightsTest.php
@@ -215,10 +215,9 @@ class ApiUserrightsTest extends ApiTestCase {
$this->doSuccessfulRightsChange( 'sysop', [ 'tags' => 'custom tag' ], $user );
- $dbr = wfGetDB( DB_REPLICA );
$this->assertSame(
'custom tag',
- $dbr->newSelectQueryBuilder()
+ $this->getDb()->newSelectQueryBuilder()
->select( 'ctd_name' )
->from( 'logging' )
->join( 'change_tag', null, 'ct_log_id = log_id' )
diff --git a/tests/phpunit/includes/api/query/ApiQueryBlockInfoTraitTest.php b/tests/phpunit/includes/api/query/ApiQueryBlockInfoTraitTest.php
index e23e156b797d..703fb4c64991 100644
--- a/tests/phpunit/includes/api/query/ApiQueryBlockInfoTraitTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryBlockInfoTraitTest.php
@@ -1,6 +1,7 @@
<?php
use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
use Wikimedia\Timestamp\ConvertibleTimestamp;
@@ -25,7 +26,7 @@ class ApiQueryBlockInfoTraitTest extends MediaWikiIntegrationTestCase {
$data = [];
$mock = $this->getMockForTrait( ApiQueryBlockInfoTrait::class );
- $mock->method( 'getDB' )->willReturn( wfGetDB( DB_REPLICA ) );
+ $mock->method( 'getDB' )->willReturn( $this->getDb() );
$mock->method( 'getAuthority' )
->willReturn( $this->getMutableTestUser()->getUser() );
$mock->method( 'addTables' )->willReturnCallback( static function ( $v ) use ( &$data ) {
@@ -48,7 +49,7 @@ class ApiQueryBlockInfoTraitTest extends MediaWikiIntegrationTestCase {
public static function provideAddBlockInfoToQuery() {
$queryInfo = DatabaseBlock::getQueryInfo();
- $db = wfGetDB( DB_REPLICA );
+ $db = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase();
$ts = $db->addQuotes( $db->timestamp( '20190101000000' ) );
return [
diff --git a/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php b/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
index 52ae188b60ca..3a7bfb6c0940 100644
--- a/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
@@ -156,15 +156,15 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
}
public function testSpecialPageAliases() {
- $this->assertCount(
- count( $this->getServiceContainer()->getSpecialPageFactory()->getNames() ),
+ $this->assertSameSize(
+ $this->getServiceContainer()->getSpecialPageFactory()->getNames(),
$this->doQuery( 'specialpagealiases' )
);
}
public function testMagicWords() {
- $this->assertCount(
- count( $this->getServiceContainer()->getContentLanguage()->getMagicWords() ),
+ $this->assertSameSize(
+ $this->getServiceContainer()->getContentLanguage()->getMagicWords(),
$this->doQuery( 'magicwords' )
);
}
@@ -181,8 +181,7 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
MainConfigNames::ScriptPath => '/w',
] );
- $dbw = wfGetDB( DB_PRIMARY );
- $dbw->insert(
+ $this->getDb()->insert(
'interwiki',
[
[
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php
index 5e1b36c21695..19e90cc61de5 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -2267,7 +2267,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
}
// We're testing with $wgNewUserLog = false, so assert that it worked
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$maxLogId = $dbw->newSelectQueryBuilder()
->select( 'MAX(log_id)' )
->from( 'logging' )
@@ -2545,7 +2545,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$this->config->set( MainConfigNames::NewUserLog, true );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$maxLogId = $dbw->newSelectQueryBuilder()
->select( 'MAX(log_id)' )
->from( 'logging' )
@@ -3025,7 +3025,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
], $logger->getBuffer() );
$logger->clearBuffer();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$maxLogId = $dbw->newSelectQueryBuilder()
->select( 'MAX(log_id)' )
->from( 'logging' )
diff --git a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
index 152cafb78453..c3de0ef850ec 100644
--- a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
@@ -126,7 +126,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
public function testTestUserCanAuthenticate() {
$user = $this->getMutableTestUser()->getUser();
$userName = $user->getName();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$provider = $this->getProvider();
@@ -172,8 +172,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
$user = $this->getMutableTestUser()->getUser();
$userName = $user->getName();
- $dbw = wfGetDB( DB_PRIMARY );
- $row = $dbw->newSelectQueryBuilder()
+ $row = $this->getDb()->newSelectQueryBuilder()
->select( '*' )
->from( 'user' )
->where( [ 'user_name' => $userName ] )
@@ -233,7 +232,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
$testUser = $this->getMutableTestUser();
$userName = $testUser->getUser()->getName();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$id = $testUser->getUser()->getId();
$req = new PasswordAuthenticationRequest();
@@ -505,7 +504,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
$oldpass = $testUser->getPassword();
$newpass = 'NewPassword';
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$oldExpiry = $dbw->newSelectQueryBuilder()
->select( 'user_password_expires' )
->from( 'user' )
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index c374d905a9f9..ec01df9eb026 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -170,7 +170,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
public function testTestUserCanAuthenticate() {
$user = self::getMutableTestUser()->getUser();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$config = $this->getServiceContainer()->getMainConfig();
// A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
$passwordFactory = new PasswordFactory( $config->get( MainConfigNames::PasswordConfig ), 'A' );
@@ -276,7 +276,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$password = 'TemporaryPassword';
$hash = ':A:' . md5( $password );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'user' )
->set( [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ] )
@@ -496,7 +496,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$oldpass = 'OldTempPassword';
$newpass = 'NewTempPassword';
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$oldHash = $dbw->newSelectQueryBuilder()
->select( 'user_newpassword' )
->from( 'user' )
@@ -603,7 +603,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
public function testProviderChangeAuthenticationDataEmail() {
$user = self::getMutableTestUser()->getUser();
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'user' )
->set( [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ] )
diff --git a/tests/phpunit/includes/block/BlockRestrictionStoreTest.php b/tests/phpunit/includes/block/BlockRestrictionStoreTest.php
index 99734ca6647c..73c43b73f5e3 100644
--- a/tests/phpunit/includes/block/BlockRestrictionStoreTest.php
+++ b/tests/phpunit/includes/block/BlockRestrictionStoreTest.php
@@ -214,8 +214,7 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
new NamespaceRestriction( $block->getId(), NS_USER ),
] );
- $db = wfGetDB( DB_REPLICA );
- $result = $db->newSelectQueryBuilder()
+ $result = $this->getDb()->newSelectQueryBuilder()
->select( [ '*' ] )
->from( 'ipblocks_restrictions' )
->where( [ 'ir_ipb_id' => $block->getId() ] )
@@ -240,8 +239,7 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
new PageRestriction( $block->getId(), $page->getId() ),
] );
- $db = wfGetDB( DB_REPLICA );
- $result = $db->newSelectQueryBuilder()
+ $result = $this->getDb()->newSelectQueryBuilder()
->select( [ '*' ] )
->from( 'ipblocks_restrictions' )
->where( [ 'ir_ipb_id' => $block->getId() ] )
@@ -263,8 +261,7 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
$this->blockRestrictionStore->update( [] );
- $db = wfGetDB( DB_REPLICA );
- $result = $db->newSelectQueryBuilder()
+ $result = $this->getDb()->newSelectQueryBuilder()
->select( [ '*' ] )
->from( 'ipblocks_restrictions' )
->where( [ 'ir_ipb_id' => $block->getId() ] )
@@ -289,8 +286,7 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
new PageRestriction( $block->getId(), $page->getId() ),
] );
- $db = wfGetDB( DB_REPLICA );
- $result = $db->newSelectQueryBuilder()
+ $result = $this->getDb()->newSelectQueryBuilder()
->select( [ '*' ] )
->from( 'ipblocks_restrictions' )
->where( [ 'ir_ipb_id' => $block->getId() ] )
diff --git a/tests/phpunit/includes/changetags/ChangeTagsTest.php b/tests/phpunit/includes/changetags/ChangeTagsTest.php
index f2c1593825ec..3773f2403874 100644
--- a/tests/phpunit/includes/changetags/ChangeTagsTest.php
+++ b/tests/phpunit/includes/changetags/ChangeTagsTest.php
@@ -30,7 +30,7 @@ class ChangeTagsTest extends MediaWikiIntegrationTestCase {
}
private function emptyChangeTagsTables() {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'change_tag' )
->where( ISQLPlatform::ALL_ROWS )
@@ -65,7 +65,7 @@ class ChangeTagsTest extends MediaWikiIntegrationTestCase {
ChangeTags::updateTags( [ 'foo', 'bar', '0' ], [], $rcId );
// HACK resolve deferred group concats (see comment in provideModifyDisplayQuery)
if ( isset( $modifiedQuery['fields']['ts_tags'] ) ) {
- $modifiedQuery['fields']['ts_tags'] = wfGetDB( DB_REPLICA )
+ $modifiedQuery['fields']['ts_tags'] = $this->getDb()
->buildGroupConcatField( ...$modifiedQuery['fields']['ts_tags'] );
}
if ( isset( $modifiedQuery['exception'] ) ) {
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php
index 1a65f7187c2f..f71a92a9f3fb 100644
--- a/tests/phpunit/includes/db/LBFactoryTest.php
+++ b/tests/phpunit/includes/db/LBFactoryTest.php
@@ -395,7 +395,7 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase {
public function testNiceDomains() {
global $wgDBname;
- if ( wfGetDB( DB_PRIMARY )->databasesAreIndependent() ) {
+ if ( $this->getDb()->databasesAreIndependent() ) {
self::markTestSkipped( "Skipping tests about selecting DBs: not applicable" );
return;
}
@@ -474,7 +474,7 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase {
public function testTrickyDomain() {
global $wgDBname;
- if ( wfGetDB( DB_PRIMARY )->databasesAreIndependent() ) {
+ if ( $this->getDb()->databasesAreIndependent() ) {
self::markTestSkipped( "Skipping tests about selecting DBs: not applicable" );
return;
}
@@ -538,7 +538,7 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase {
}
public function testInvalidSelectDB() {
- if ( wfGetDB( DB_PRIMARY )->databasesAreIndependent() ) {
+ if ( $this->getDb()->databasesAreIndependent() ) {
$this->markTestSkipped( "Not applicable per databasesAreIndependent()" );
}
@@ -602,7 +602,7 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase {
public function testRedefineLocalDomain() {
global $wgDBname;
- if ( wfGetDB( DB_PRIMARY )->databasesAreIndependent() ) {
+ if ( $this->getDb()->databasesAreIndependent() ) {
self::markTestSkipped( "Skipping tests about selecting DBs: not applicable" );
return;
}
diff --git a/tests/phpunit/includes/deferred/LinksUpdateTest.php b/tests/phpunit/includes/deferred/LinksUpdateTest.php
index dda8b68383bd..c570af2db9d4 100644
--- a/tests/phpunit/includes/deferred/LinksUpdateTest.php
+++ b/tests/phpunit/includes/deferred/LinksUpdateTest.php
@@ -828,8 +828,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
$this->setTransactionTicket( $update );
$update->doUpdate();
- $dbw = wfGetDB( DB_PRIMARY );
- $time1 = $dbw->lastDoneWrites();
+ $time1 = $this->getDb()->lastDoneWrites();
$this->assertGreaterThan( 0, $time1 );
$update = new class( $t, $po ) extends LinksUpdate {
@@ -839,7 +838,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
};
$update->setStrictTestMode();
$update->doUpdate();
- $time2 = wfGetDB( DB_PRIMARY )->lastDoneWrites();
+ $time2 = $this->getDb()->lastDoneWrites();
$this->assertSame( $time1, $time2 );
}
diff --git a/tests/phpunit/includes/deferred/RefreshSecondaryDataUpdateTest.php b/tests/phpunit/includes/deferred/RefreshSecondaryDataUpdateTest.php
index 57883c3663ed..1772245297a0 100644
--- a/tests/phpunit/includes/deferred/RefreshSecondaryDataUpdateTest.php
+++ b/tests/phpunit/includes/deferred/RefreshSecondaryDataUpdateTest.php
@@ -45,7 +45,7 @@ class RefreshSecondaryDataUpdateTest extends MediaWikiIntegrationTestCase {
$revision->method( 'getId' )
->willReturn( 42 );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->startAtomic( __METHOD__ );
@@ -123,7 +123,7 @@ class RefreshSecondaryDataUpdateTest extends MediaWikiIntegrationTestCase {
$revision->method( 'getId' )
->willReturn( 42 );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->startAtomic( __METHOD__ );
$goodCalls = 0;
diff --git a/tests/phpunit/includes/deferred/SiteStatsUpdateTest.php b/tests/phpunit/includes/deferred/SiteStatsUpdateTest.php
index cb1ecf0daf54..9787b61e7ce7 100644
--- a/tests/phpunit/includes/deferred/SiteStatsUpdateTest.php
+++ b/tests/phpunit/includes/deferred/SiteStatsUpdateTest.php
@@ -26,7 +26,7 @@ class SiteStatsUpdateTest extends MediaWikiIntegrationTestCase {
}
public function testDoUpdate() {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$statsInit = new SiteStatsInit( $dbw );
$statsInit->refresh();
diff --git a/tests/phpunit/includes/editpage/EditPageConstraintsTest.php b/tests/phpunit/includes/editpage/EditPageConstraintsTest.php
index db91f8ef7007..bffc35be16b5 100644
--- a/tests/phpunit/includes/editpage/EditPageConstraintsTest.php
+++ b/tests/phpunit/includes/editpage/EditPageConstraintsTest.php
@@ -89,7 +89,7 @@ class EditPageConstraintsTest extends MediaWikiLangTestCase {
$page->doUserEditContent( $content, $user, "base text for test" );
// Set the latest timestamp back a while
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'revision' )
->set( [ 'rev_timestamp' => $dbw->timestamp( '20120101000000' ) ] )
@@ -167,7 +167,7 @@ class EditPageConstraintsTest extends MediaWikiLangTestCase {
// Set the time of the deletion to be a specific time, so we can be sure to start the
// edit before it. Since the constraint will query for the most recent timestamp,
// update *all* deletion logs for the page to the same timestamp (1 January 2020)
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'logging' )
->set( [ 'log_timestamp' => $dbw->timestamp( '20200101000000' ) ] )
diff --git a/tests/phpunit/includes/editpage/EditPageTest.php b/tests/phpunit/includes/editpage/EditPageTest.php
index 8e23c14a941f..5b62757e9856 100644
--- a/tests/phpunit/includes/editpage/EditPageTest.php
+++ b/tests/phpunit/includes/editpage/EditPageTest.php
@@ -75,7 +75,7 @@ class EditPageTest extends MediaWikiLangTestCase {
}
protected function forceRevisionDate( WikiPage $page, $timestamp ) {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'revision' )
@@ -337,7 +337,7 @@ class EditPageTest extends MediaWikiLangTestCase {
}
);
- wfGetDB( DB_PRIMARY )->begin( __METHOD__ );
+ $this->getDb()->begin( __METHOD__ );
$edit = [ 'wpTextbox1' => $editText ];
if ( $ignoreBlank ) {
@@ -351,7 +351,7 @@ class EditPageTest extends MediaWikiLangTestCase {
$page2 = $this->assertEdit(
$pageTitle2, null, $user, $edit, $expectedCode, $expectedText, $desc );
- wfGetDB( DB_PRIMARY )->commit( __METHOD__ );
+ $this->getDb()->commit( __METHOD__ );
$this->assertSame( 0, DeferredUpdates::pendingUpdatesCount(), 'No deferred updates' );
@@ -497,7 +497,7 @@ class EditPageTest extends MediaWikiLangTestCase {
}
);
- wfGetDB( DB_PRIMARY )->begin( __METHOD__ );
+ $this->getDb()->begin( __METHOD__ );
$text = "two";
$edit = [
@@ -519,7 +519,7 @@ class EditPageTest extends MediaWikiLangTestCase {
EditPage::AS_SUCCESS_UPDATE, $text,
"expected successful update with given text" );
- wfGetDB( DB_PRIMARY )->commit( __METHOD__ );
+ $this->getDb()->commit( __METHOD__ );
$this->assertGreaterThan( 0, $checkIds[0], "First event rev ID set" );
$this->assertGreaterThan( 0, $checkIds[1], "Second edit hook rev ID set" );
diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
index 2c8a7725fe44..ae71a6ba52ba 100644
--- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php
+++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
@@ -561,7 +561,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
] )
);
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$norm = $services->getActorNormalization();
$user = $this->getTestSysop()->getUserIdentity();
$actorId = $norm->acquireActorId( $user, $dbw );
@@ -916,7 +916,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideReserializeMetadata
*/
public function testReserializeMetadata( $input, $expected ) {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$services = $this->getServiceContainer();
$norm = $services->getActorNormalization();
$user = $this->getTestSysop()->getUserIdentity();
@@ -990,7 +990,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
'containerPaths' => [ 'test-public' => __DIR__ . '/../../../data/media' ]
] )
] );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$services = $this->getServiceContainer();
$norm = $services->getActorNormalization();
$user = $this->getTestSysop()->getUserIdentity();
diff --git a/tests/phpunit/includes/import/ImportTest.php b/tests/phpunit/includes/import/ImportTest.php
index b5a4e0a88393..ef464aa4497c 100644
--- a/tests/phpunit/includes/import/ImportTest.php
+++ b/tests/phpunit/includes/import/ImportTest.php
@@ -288,7 +288,7 @@ EOF
$importer->setUsernamePrefix( 'Xxx', $assign );
$importer->doImport();
- $db = wfGetDB( DB_PRIMARY );
+ $db = $this->getDb();
$row = $services->getRevisionStore()->newSelectQueryBuilder( $db )
->where( [ 'rev_timestamp' => $db->timestamp( "201601010{$n}0000" ) ] )
->caller( __METHOD__ )->fetchRow();
diff --git a/tests/phpunit/includes/interwiki/InterwikiTest.php b/tests/phpunit/includes/interwiki/InterwikiTest.php
index 8c2e6733abda..a5f468c64609 100644
--- a/tests/phpunit/includes/interwiki/InterwikiTest.php
+++ b/tests/phpunit/includes/interwiki/InterwikiTest.php
@@ -43,7 +43,7 @@ class InterwikiTest extends MediaWikiIntegrationTestCase {
//// tests for static data access methods below ///////////////////////////////////////////////
private function populateDB( $iwrows ) {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'interwiki' )
->where( ISQLPlatform::ALL_ROWS )
diff --git a/tests/phpunit/includes/language/MessageCacheTest.php b/tests/phpunit/includes/language/MessageCacheTest.php
index ba1b33200488..7ff81d4233ed 100644
--- a/tests/phpunit/includes/language/MessageCacheTest.php
+++ b/tests/phpunit/includes/language/MessageCacheTest.php
@@ -112,7 +112,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
$uckey = $this->getServiceContainer()->getContentLanguage()->ucfirst( $message );
$oldText = $messageCache->get( $message ); // "Ausführen"
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->startAtomic( __METHOD__ ); // simulate request and block deferred updates
$messageCache->replace( $uckey, 'Allez!' );
$this->assertEquals( 'Allez!',
@@ -194,7 +194,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
public function testNoDBAccessContentLanguage() {
global $wgLanguageCode;
- $dbr = wfGetDB( DB_REPLICA );
+ $dbr = $this->getDb();
$messageCache = $this->getServiceContainer()->getMessageCache();
$messageCache->getMsgFromNamespace( 'allpages', $wgLanguageCode );
@@ -210,7 +210,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
}
public function testNoDBAccessNonContentLanguage() {
- $dbr = wfGetDB( DB_REPLICA );
+ $dbr = $this->getDb();
$messageCache = $this->getServiceContainer()->getMessageCache();
$messageCache->getMsgFromNamespace( 'allpages/nl', 'nl' );
diff --git a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
index 0ab971d10b40..1b6c264289e1 100644
--- a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
+++ b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
@@ -59,7 +59,7 @@ class MultiWriteBagOStuffTest extends MediaWikiIntegrationTestCase {
};
// XXX: DeferredUpdates bound to transactions in CLI mode
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->begin();
$this->cache->merge( $key, $func );
@@ -88,7 +88,7 @@ class MultiWriteBagOStuffTest extends MediaWikiIntegrationTestCase {
$key = 'keyB';
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->begin();
$cache->merge( $key, $func );
@@ -106,7 +106,7 @@ class MultiWriteBagOStuffTest extends MediaWikiIntegrationTestCase {
$expectValue = clone $value;
// XXX: DeferredUpdates bound to transactions in CLI mode
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->begin();
$this->cache->set( $key, $value );
diff --git a/tests/phpunit/includes/page/PageArchiveTest.php b/tests/phpunit/includes/page/PageArchiveTest.php
index eeb2db7b992e..ad5e30999802 100644
--- a/tests/phpunit/includes/page/PageArchiveTest.php
+++ b/tests/phpunit/includes/page/PageArchiveTest.php
@@ -94,7 +94,7 @@ class PageArchiveTest extends MediaWikiIntegrationTestCase {
$rev->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
$rev->setComment( CommentStoreComment::newUnsavedComment( 'just a test' ) );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$this->ipRev = $revisionStore->insertRevisionOn( $rev, $dbw );
$this->deletePage( $page, '', $user );
diff --git a/tests/phpunit/includes/page/WikiPageDbTest.php b/tests/phpunit/includes/page/WikiPageDbTest.php
index b89419826355..7d8362298e6d 100644
--- a/tests/phpunit/includes/page/WikiPageDbTest.php
+++ b/tests/phpunit/includes/page/WikiPageDbTest.php
@@ -249,8 +249,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
// TODO: test various options; needs temporary hooks
- $dbr = wfGetDB( DB_REPLICA );
- $res = $dbr->newSelectQueryBuilder()
+ $res = $this->getDb()->newSelectQueryBuilder()
->select( '*' )
->from( 'pagelinks' )
->where( [ 'pl_from' => $page->getId() ] )
@@ -325,8 +324,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
$this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
# ------------------------
- $dbr = wfGetDB( DB_REPLICA );
- $res = $dbr->newSelectQueryBuilder()
+ $res = $this->getDb()->newSelectQueryBuilder()
->select( '*' )
->from( 'pagelinks' )
->where( [ 'pl_from' => $id ] )
@@ -392,8 +390,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
$this->assertStringNotContainsString( '~~~~', $newText, 'PST must substitute signature.' );
# ------------------------
- $dbr = wfGetDB( DB_REPLICA );
- $res = $dbr->newSelectQueryBuilder()
+ $res = $this->getDb()->newSelectQueryBuilder()
->select( '*' )
->from( 'pagelinks' )
->where( [ 'pl_from' => $id ] )
@@ -512,8 +509,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
$this->runJobs();
# ------------------------
- $dbr = wfGetDB( DB_REPLICA );
- $res = $dbr->newSelectQueryBuilder()
+ $res = $this->getDb()->newSelectQueryBuilder()
->select( '*' )
->from( 'pagelinks' )
->where( [ 'pl_from' => $id ] )
@@ -1967,7 +1963,7 @@ more stuff
$title = Title::makeTitleSafe( NS_MAIN, 'A new redirect' );
$this->assertFalse( $title->isRedirect() );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$store = $this->getServiceContainer()->getRevisionStore();
$page = $this->newPage( $title );
$page->insertOn( $dbw );
diff --git a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
index b648f82ad3bc..d40e2915c402 100644
--- a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
+++ b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
@@ -21,10 +21,9 @@ class ReverseChronologicalPagerTest extends MediaWikiIntegrationTestCase {
public function testGetDateCond( $params, $expected ) {
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
- $db = wfGetDB( DB_PRIMARY );
$pager->getDateCond( ...$params );
- $this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $expected ) );
+ $this->assertEquals( $pagerWrapper->endOffset, $this->getDb()->timestamp( $expected ) );
}
/**
@@ -70,7 +69,7 @@ class ReverseChronologicalPagerTest extends MediaWikiIntegrationTestCase {
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
$timestamp = MWTimestamp::getInstance();
- $db = wfGetDB( DB_PRIMARY );
+ $db = $this->getDb();
$currYear = $timestamp->format( 'Y' );
$currMonth = $timestamp->format( 'n' );
diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
index faeede798657..6ad1399bb58b 100644
--- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
+++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
@@ -82,7 +82,7 @@ class BotPasswordSessionProviderTest extends MediaWikiIntegrationTestCase {
->getLookup( 'local' )
->centralIdFromName( $sysop->getName() );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'bot_passwords' )
->where( [ 'bp_user' => $userId, 'bp_app_id' => 'BotPasswordSessionProvider' ] )
diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php
index 25f4156565b5..954ee59d3179 100644
--- a/tests/phpunit/includes/user/BotPasswordTest.php
+++ b/tests/phpunit/includes/user/BotPasswordTest.php
@@ -67,7 +67,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
$passwordFactory = $this->getServiceContainer()->getPasswordFactory();
$passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'bot_passwords' )
->where( [ 'bp_user' => [ 42, 43 ], 'bp_app_id' => 'BotPassword' ] )
@@ -194,7 +194,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
$this->assertInstanceOf( InvalidPassword::class, $password );
$bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newUpdateQueryBuilder()
->update( 'bot_passwords' )
->set( [ 'bp_password' => 'garbage' ] )
diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php
index 5eb3cc719c02..f2552833f962 100644
--- a/tests/phpunit/includes/user/UserTest.php
+++ b/tests/phpunit/includes/user/UserTest.php
@@ -619,7 +619,7 @@ class UserTest extends MediaWikiIntegrationTestCase {
MainConfigNames::ExperiencedUserMemberSince => 30,
] );
- $db = wfGetDB( DB_PRIMARY );
+ $db = $this->getDb();
$row = User::newQueryBuilder( $db )
->where( [ 'user_id' => $this->user->getId() ] )
->caller( __METHOD__ )