aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api
diff options
context:
space:
mode:
authorAmir Sarabadani <ladsgroup@gmail.com>2023-09-25 20:49:16 +0200
committerAmir Sarabadani <ladsgroup@gmail.com>2023-09-25 21:08:09 +0200
commitcd2e19c050002f2ea1165d0fcccb3bb9ed1d7631 (patch)
treef7c22cf1bec4bb9221d3be40e8d7b95987b0f056 /tests/phpunit/includes/api
parent60b986e6321785642a577d48f7d4e7d8b2a20893 (diff)
downloadmediawikicore-cd2e19c050002f2ea1165d0fcccb3bb9ed1d7631.tar.gz
mediawikicore-cd2e19c050002f2ea1165d0fcccb3bb9ed1d7631.zip
tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago. Bug: T330641 Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
Diffstat (limited to 'tests/phpunit/includes/api')
-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
11 files changed, 20 insertions, 30 deletions
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',
[
[