aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes')
-rw-r--r--tests/phpunit/includes/Category/CategoryTest.php12
-rw-r--r--tests/phpunit/includes/CommentStore/CommentStoreTest.php19
-rw-r--r--tests/phpunit/includes/Revision/RevisionStoreDbTest.php5
-rw-r--r--tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php25
-rw-r--r--tests/phpunit/includes/Storage/PageUpdaterTest.php24
-rw-r--r--tests/phpunit/includes/api/ApiBlockTest.php40
-rw-r--r--tests/phpunit/includes/api/ApiChangeContentModelTest.php11
-rw-r--r--tests/phpunit/includes/api/ApiDeleteTest.php21
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php14
-rw-r--r--tests/phpunit/includes/api/ApiUnblockTest.php18
-rw-r--r--tests/phpunit/includes/api/ApiUserrightsTest.php19
-rw-r--r--tests/phpunit/includes/auth/AuthManagerTest.php32
-rw-r--r--tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php6
-rw-r--r--tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php12
-rw-r--r--tests/phpunit/includes/block/BlockManagerTest.php9
-rw-r--r--tests/phpunit/includes/block/DatabaseBlockTest.php11
-rw-r--r--tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php12
-rw-r--r--tests/phpunit/includes/filerepo/file/LocalFileTest.php16
-rw-r--r--tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php22
-rw-r--r--tests/phpunit/includes/page/PageStoreTest.php10
-rw-r--r--tests/phpunit/includes/page/WikiPageDbTest.php31
-rw-r--r--tests/phpunit/includes/session/UserInfoTest.php7
-rw-r--r--tests/phpunit/includes/specials/SpecialBlockTest.php11
-rw-r--r--tests/phpunit/includes/title/TitleTest.php10
-rw-r--r--tests/phpunit/includes/user/UserTest.php8
-rw-r--r--tests/phpunit/includes/watcheditem/WatchedItemStoreIntegrationTest.php15
26 files changed, 232 insertions, 188 deletions
diff --git a/tests/phpunit/includes/Category/CategoryTest.php b/tests/phpunit/includes/Category/CategoryTest.php
index 6054577c82d5..479b98ebebda 100644
--- a/tests/phpunit/includes/Category/CategoryTest.php
+++ b/tests/phpunit/includes/Category/CategoryTest.php
@@ -105,12 +105,12 @@ class CategoryTest extends MediaWikiIntegrationTestCase {
public function testNewFromRow_found() {
$dbw = wfGetDB( DB_PRIMARY );
- $category = Category::newFromRow( $dbw->selectRow(
- 'category',
- [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
- [ 'cat_id' => 1 ],
- __METHOD__
- ) );
+ $category = Category::newFromRow( $dbw->newSelectQueryBuilder()
+ ->select( [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ] )
+ ->from( 'category' )
+ ->where( [ 'cat_id' => 1 ] )
+ ->caller( __METHOD__ )->fetchRow()
+ );
$this->assertSame( '1', $category->getID() );
}
diff --git a/tests/phpunit/includes/CommentStore/CommentStoreTest.php b/tests/phpunit/includes/CommentStore/CommentStoreTest.php
index f435a94abe4b..461d0684e8d8 100644
--- a/tests/phpunit/includes/CommentStore/CommentStoreTest.php
+++ b/tests/phpunit/includes/CommentStore/CommentStoreTest.php
@@ -174,12 +174,11 @@ class CommentStoreTest extends MediaWikiLangTestCase {
$rstore = $this->makeStore();
- $fieldRow = $this->db->selectRow(
- $table,
- $rstore->getFields( $key ),
- [ $pk => $id ],
- __METHOD__
- );
+ $fieldRow = $this->db->newSelectQueryBuilder()
+ ->select( $rstore->getFields( $key ) )
+ ->from( $table )
+ ->where( [ $pk => $id ] )
+ ->caller( __METHOD__ )->fetchRow();
$queryInfo = $rstore->getJoin( $key );
$joinRow = $this->db->selectRow(
@@ -308,9 +307,11 @@ class CommentStoreTest extends MediaWikiLangTestCase {
$store = $this->makeStore();
$fields = $store->insert( $this->db, 'ipb_reason', $comment );
- $stored = $this->db->selectField(
- 'comment', 'comment_text', [ 'comment_id' => $fields['ipb_reason_id'] ], __METHOD__
- );
+ $stored = $this->db->newSelectQueryBuilder()
+ ->select( 'comment_text' )
+ ->from( 'comment' )
+ ->where( [ 'comment_id' => $fields['ipb_reason_id'] ] )
+ ->caller( __METHOD__ )->fetchField();
$this->assertSame( $truncated, $stored );
}
diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
index 80cdfa147ffa..5de038fbcdbb 100644
--- a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
+++ b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
@@ -3015,7 +3015,10 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
// NOTE: must be done before checking MAX(rev_id)
$page = $this->getTestPage();
- $maxRevId = $this->getDb()->selectField( 'revision', 'MAX(rev_id)' );
+ $maxRevId = $this->getDb()->newSelectQueryBuilder()
+ ->select( 'MAX(rev_id)' )
+ ->from( 'revision' )
+ ->fetchField();
// Construct a slot row that will conflict with the insertion of the next revision ID,
// to emulate the failure mode described in T202032. Nothing will ever read this row,
diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
index 8a647652daf8..5b87405880a7 100644
--- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
@@ -1090,7 +1090,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase {
$rev = $this->createRevision( $page, 'first', $content );
$pageId = $page->getId();
- $oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $oldStats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$this->db->delete( 'pagelinks', '*' );
$pcache = $this->getServiceContainer()->getParserCache();
@@ -1105,13 +1109,12 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase {
$updater->doUpdates();
// links table update
- $pageLinks = $this->db->select(
- 'pagelinks',
- '*',
- [ 'pl_from' => $pageId ],
- __METHOD__,
- [ 'ORDER BY' => [ 'pl_namespace', 'pl_title' ] ]
- );
+ $pageLinks = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'pagelinks' )
+ ->where( [ 'pl_from' => $pageId ] )
+ ->orderBy( [ 'pl_namespace', 'pl_title' ] )
+ ->caller( __METHOD__ )->fetchResultSet();
$pageLinksRow = $pageLinks->fetchObject();
$this->assertIsObject( $pageLinksRow );
@@ -1127,7 +1130,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase {
$this->assertEquals( $updater->getCanonicalParserOutput(), $cached );
// site stats
- $stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $stats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$this->assertSame( $oldStats->ss_total_pages + 1, (int)$stats->ss_total_pages );
$this->assertSame( $oldStats->ss_total_edits + 1, (int)$stats->ss_total_edits );
$this->assertSame( $oldStats->ss_good_articles + 1, (int)$stats->ss_good_articles );
diff --git a/tests/phpunit/includes/Storage/PageUpdaterTest.php b/tests/phpunit/includes/Storage/PageUpdaterTest.php
index e5a95b44a52b..eaf9ca598e19 100644
--- a/tests/phpunit/includes/Storage/PageUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/PageUpdaterTest.php
@@ -92,7 +92,11 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
$page = $wikiPageFactory->newFromTitle( $title );
$updater = $page->newPageUpdater( $user );
- $oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $oldStats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
@@ -168,7 +172,11 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
$this->assertNotNull( $rc, 'RecentChange' );
// check site stats - this asserts that derived data updates where run.
- $stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $stats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$this->assertSame( $oldStats->ss_total_pages + 1, (int)$stats->ss_total_pages );
$this->assertSame( $oldStats->ss_total_edits + 1, (int)$stats->ss_total_edits );
@@ -203,7 +211,11 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
$updater = $page->newPageUpdater( $user );
- $oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $oldStats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$updater->setOriginalRevisionId( 7 );
@@ -300,7 +312,11 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
);
// check site stats - this asserts that derived data updates where run.
- $stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
+ $stats = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'site_stats' )
+ ->where( '1=1' )
+ ->fetchRow();
$this->assertNotNull( $stats, 'site_stats' );
$this->assertSame( $oldStats->ss_total_pages + 0, (int)$stats->ss_total_pages );
$this->assertSame( $oldStats->ss_total_edits + 2, (int)$stats->ss_total_edits );
diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php
index 475b5bbb6308..aebc1d3f0929 100644
--- a/tests/phpunit/includes/api/ApiBlockTest.php
+++ b/tests/phpunit/includes/api/ApiBlockTest.php
@@ -123,17 +123,13 @@ class ApiBlockTest extends ApiTestCase {
$this->doBlock( [ 'tags' => 'custom tag' ] );
$dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 1, (int)$dbw->selectField(
- [ 'change_tag', 'logging', 'change_tag_def' ],
- 'COUNT(*)',
- [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ],
- __METHOD__,
- [],
- [
- 'change_tag' => [ 'JOIN', 'ct_log_id = log_id' ],
- 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ],
- ]
- ) );
+ $this->assertSame( 1, (int)$dbw->newSelectQueryBuilder()
+ ->select( 'COUNT(*)' )
+ ->from( 'logging' )
+ ->join( 'change_tag', null, 'ct_log_id = log_id' )
+ ->join( 'change_tag_def', null, 'ctd_id = ct_tag_id' )
+ ->where( [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testBlockWithProhibitedTag() {
@@ -155,12 +151,11 @@ class ApiBlockTest extends ApiTestCase {
new UltimateAuthority( $this->getTestSysop()->getUser() )
);
- $this->assertSame( '1', $this->db->selectField(
- 'ipblocks',
- 'ipb_deleted',
- [ 'ipb_id' => $res[0]['block']['id'] ],
- __METHOD__
- ) );
+ $this->assertSame( '1', $this->db->newSelectQueryBuilder()
+ ->select( 'ipb_deleted' )
+ ->from( 'ipblocks' )
+ ->where( [ 'ipb_id' => $res[0]['block']['id'] ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testBlockWithProhibitedHide() {
@@ -182,12 +177,11 @@ class ApiBlockTest extends ApiTestCase {
$res = $this->doBlock( [ 'noemail' => '' ] );
$dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( '1', $dbw->selectField(
- 'ipblocks',
- 'ipb_block_email',
- [ 'ipb_id' => $res[0]['block']['id'] ],
- __METHOD__
- ) );
+ $this->assertSame( '1', $dbw->newSelectQueryBuilder()
+ ->select( 'ipb_block_email' )
+ ->from( 'ipblocks' )
+ ->where( [ 'ipb_id' => $res[0]['block']['id'] ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testBlockWithProhibitedEmailBlock() {
diff --git a/tests/phpunit/includes/api/ApiChangeContentModelTest.php b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
index 82b89503b050..7ba861ab6bec 100644
--- a/tests/phpunit/includes/api/ApiChangeContentModelTest.php
+++ b/tests/phpunit/includes/api/ApiChangeContentModelTest.php
@@ -324,12 +324,11 @@ class ApiChangeContentModelTest extends ApiTestCase {
$dbw = wfGetDB( DB_PRIMARY );
$this->assertSame(
'4',
- $dbw->selectField(
- [ 'change_tag_def' ],
- 'ctd_count',
- [ 'ctd_name' => 'api edit content model tag' ],
- __METHOD__
- ),
+ $dbw->newSelectQueryBuilder()
+ ->select( 'ctd_count' )
+ ->from( 'change_tag_def' )
+ ->where( [ 'ctd_name' => 'api edit content model tag' ] )
+ ->caller( __METHOD__ )->fetchField(),
'There should be four uses of the `api edit content model tag` tag, '
. 'two for the two revisions and two for the two log entries'
);
diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php b/tests/phpunit/includes/api/ApiDeleteTest.php
index 2f26ebed427a..497c49ea376f 100644
--- a/tests/phpunit/includes/api/ApiDeleteTest.php
+++ b/tests/phpunit/includes/api/ApiDeleteTest.php
@@ -149,20 +149,13 @@ class ApiDeleteTest extends ApiTestCase {
$this->assertFalse( $title->exists( Title::READ_LATEST ) );
$dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 'custom tag', $dbw->selectField(
- [ 'change_tag', 'logging', 'change_tag_def' ],
- 'ctd_name',
- [
- 'log_namespace' => $title->getNamespace(),
- 'log_title' => $title->getDBkey(),
- ],
- __METHOD__,
- [],
- [
- 'change_tag' => [ 'JOIN', 'ct_log_id = log_id' ],
- 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ]
- ]
- ) );
+ $this->assertSame( 'custom tag', $dbw->newSelectQueryBuilder()
+ ->select( 'ctd_name' )
+ ->from( 'logging' )
+ ->join( 'change_tag', null, 'ct_log_id = log_id' )
+ ->join( 'change_tag_def', null, 'ctd_id = ct_tag_id' )
+ ->where( [ 'log_namespace' => $title->getNamespace(), 'log_title' => $title->getDBkey(), ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testDeleteWithoutTagPermission() {
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 6a8125ee4085..3f0854d65f91 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -1536,14 +1536,12 @@ class ApiEditPageTest extends ApiTestCase {
'tags' => 'custom tag',
] )[0]['edit']['newrevid'];
- $this->assertSame( 'custom tag', $this->getDb()->selectField(
- [ 'change_tag', 'change_tag_def' ],
- 'ctd_name',
- [ 'ct_rev_id' => $revId ],
- __METHOD__,
- [ 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ] ]
- )
- );
+ $this->assertSame( 'custom tag', $this->getDb()->newSelectQueryBuilder()
+ ->select( 'ctd_name' )
+ ->from( 'change_tag' )
+ ->join( 'change_tag_def', null, 'ctd_id = ct_tag_id' )
+ ->where( [ 'ct_rev_id' => $revId ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testEditWithoutTagPermission() {
diff --git a/tests/phpunit/includes/api/ApiUnblockTest.php b/tests/phpunit/includes/api/ApiUnblockTest.php
index 8ee41197101d..ffec687600a7 100644
--- a/tests/phpunit/includes/api/ApiUnblockTest.php
+++ b/tests/phpunit/includes/api/ApiUnblockTest.php
@@ -123,17 +123,13 @@ class ApiUnblockTest extends ApiTestCase {
$this->doUnblock( [ 'tags' => 'custom tag' ] );
$dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 1, (int)$dbw->selectField(
- [ 'change_tag', 'logging', 'change_tag_def' ],
- 'COUNT(*)',
- [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ],
- __METHOD__,
- [],
- [
- 'change_tag' => [ 'JOIN', 'ct_log_id = log_id' ],
- 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ],
- ]
- ) );
+ $this->assertSame( 1, (int)$dbw->newSelectQueryBuilder()
+ ->select( 'COUNT(*)' )
+ ->from( 'logging' )
+ ->join( 'change_tag', null, 'ct_log_id = log_id' )
+ ->join( 'change_tag_def', null, 'ctd_id = ct_tag_id' )
+ ->where( [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testUnblockWithProhibitedTag() {
diff --git a/tests/phpunit/includes/api/ApiUserrightsTest.php b/tests/phpunit/includes/api/ApiUserrightsTest.php
index 6335f5ea27a9..bef4019705f1 100644
--- a/tests/phpunit/includes/api/ApiUserrightsTest.php
+++ b/tests/phpunit/includes/api/ApiUserrightsTest.php
@@ -218,18 +218,13 @@ class ApiUserrightsTest extends ApiTestCase {
$dbr = wfGetDB( DB_REPLICA );
$this->assertSame(
'custom tag',
- $dbr->selectField(
- [ 'change_tag', 'logging', 'change_tag_def' ],
- 'ctd_name',
- [
- 'ct_log_id = log_id',
- 'log_namespace' => NS_USER,
- 'log_title' => strtr( $user->getName(), ' ', '_' )
- ],
- __METHOD__,
- [ 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ] ]
- )
- );
+ $dbr->newSelectQueryBuilder()
+ ->select( 'ctd_name' )
+ ->from( 'logging' )
+ ->join( 'change_tag', null, 'ct_log_id = log_id' )
+ ->join( 'change_tag_def', null, 'ctd_id = ct_tag_id' )
+ ->where( [ 'log_namespace' => NS_USER, 'log_title' => strtr( $user->getName(), ' ', '_' ) ] )
+ ->caller( __METHOD__ )->fetchField() );
}
public function testWithoutTagPermission() {
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php
index ea575e6547c5..286b6f33548e 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -531,7 +531,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
} ),
/* $timeSinceAuth*/ $mutableSession
? $this->equalToWithDelta( 500, 2 )
- : $this->equalTo( -1 )
+ : -1
)
->willReturnCallback( static function ( &$v ) use ( $hook ) {
$v = $hook;
@@ -2285,7 +2285,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$this->callback( static function ( $user ) use ( $username ) {
return $user->getName() === $username;
} ),
- $this->equalTo( false )
+ false
);
$expectLog[] = [ LogLevel::INFO, "Creating user {user} during account creation" ];
} else {
@@ -2383,8 +2383,11 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$this->assertSame(
$maxLogId,
- $dbw->selectField( 'logging', 'MAX(log_id)', [ 'log_type' => 'newusers' ] )
- );
+ $dbw->newSelectQueryBuilder()
+ ->select( 'MAX(log_id)' )
+ ->from( 'logging' )
+ ->where( [ 'log_type' => 'newusers' ] )
+ ->fetchField() );
}
public function provideAccountCreation() {
@@ -2636,7 +2639,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$mocks['pre']->expects( $this->exactly( 13 ) )->method( 'testUserForCreation' )
->with( $callback, $callback2 )
- ->will( $this->onConsecutiveCalls(
+ ->willReturnOnConsecutiveCalls(
$ok, $ok, $ok, // For testing permissions
StatusValue::newFatal( 'fail-in-pre' ), $good, $good,
$good, // backoff test
@@ -2644,7 +2647,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$good, // addToDatabase throws test
$good, // addToDatabase exists test
$good, $good, $good // success
- ) );
+ );
$mocks['primary']->method( 'accountCreationType' )
->willReturn( PrimaryAuthenticationProvider::TYPE_CREATE );
@@ -2652,27 +2655,27 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
->willReturn( true );
$mocks['primary']->expects( $this->exactly( 9 ) )->method( 'testUserForCreation' )
->with( $callback, $callback2 )
- ->will( $this->onConsecutiveCalls(
+ ->willReturnOnConsecutiveCalls(
StatusValue::newFatal( 'fail-in-primary' ), $good,
$good, // backoff test
$good, // addToDatabase fails test
$good, // addToDatabase throws test
$good, // addToDatabase exists test
$good, $good, $good
- ) );
+ );
$mocks['primary']->expects( $this->exactly( 3 ) )->method( 'autoCreatedAccount' )
->with( $callback, $callback2 );
$mocks['secondary']->expects( $this->exactly( 8 ) )->method( 'testUserForCreation' )
->with( $callback, $callback2 )
- ->will( $this->onConsecutiveCalls(
+ ->willReturnOnConsecutiveCalls(
StatusValue::newFatal( 'fail-in-secondary' ),
$good, // backoff test
$good, // addToDatabase fails test
$good, // addToDatabase throws test
$good, // addToDatabase exists test
$good, $good, $good
- ) );
+ );
$mocks['secondary']->expects( $this->exactly( 3 ) )->method( 'autoCreatedAccount' )
->with( $callback, $callback2 );
@@ -2967,7 +2970,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$user = $this->getMockBuilder( User::class )
->onlyMethods( [ 'addToDatabase' ] )->getMock();
$user->expects( $this->once() )->method( 'addToDatabase' )
- ->will( $this->throwException( new \Exception( 'Excepted' ) ) );
+ ->willThrowException( new \Exception( 'Excepted' ) );
$user->setName( $username );
try {
$this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true, true );
@@ -3053,8 +3056,11 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$logger->clearBuffer();
$this->assertSame(
$maxLogId,
- $dbw->selectField( 'logging', 'MAX(log_id)', [ 'log_type' => 'newusers' ] )
- );
+ $dbw->newSelectQueryBuilder()
+ ->select( 'MAX(log_id)' )
+ ->from( 'logging' )
+ ->where( [ 'log_type' => 'newusers' ] )
+ ->fetchField() );
$this->config->set( MainConfigNames::NewUserLog, true );
$session->clear();
diff --git a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
index 5af513831dd2..152cafb78453 100644
--- a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
@@ -600,7 +600,11 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
$expectExpiry,
wfTimestampOrNull(
TS_MW,
- $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] )
+ $dbw->newSelectQueryBuilder()
+ ->select( 'user_password_expires' )
+ ->from( 'user' )
+ ->where( [ 'user_name' => $cuser ] )
+ ->fetchField()
)
);
}
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index 1b004c9d091d..c374d905a9f9 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -565,7 +565,11 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
'new password should pass'
);
$this->assertNotNull(
- $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $user ] )
+ $dbw->newSelectQueryBuilder()
+ ->select( 'user_newpass_time' )
+ ->from( 'user' )
+ ->where( [ 'user_name' => $user ] )
+ ->fetchField()
);
} else {
$this->assertEquals(
@@ -579,7 +583,11 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
'new password should fail'
);
$this->assertNull(
- $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $user ] )
+ $dbw->newSelectQueryBuilder()
+ ->select( 'user_newpass_time' )
+ ->from( 'user' )
+ ->where( [ 'user_name' => $user ] )
+ ->fetchField()
);
}
}
diff --git a/tests/phpunit/includes/block/BlockManagerTest.php b/tests/phpunit/includes/block/BlockManagerTest.php
index 0aeb26274bb7..4de5d8b03825 100644
--- a/tests/phpunit/includes/block/BlockManagerTest.php
+++ b/tests/phpunit/includes/block/BlockManagerTest.php
@@ -580,15 +580,6 @@ class BlockManagerTest extends MediaWikiIntegrationTestCase {
];
}
- public function testShouldTrackBlockWithCookieSystemBlock() {
- /** @var BlockManager $blockManager */
- $blockManager = TestingAccessWrapper::newFromObject( $this->getBlockManager( [] ) );
- $this->assertFalse( $blockManager->shouldTrackBlockWithCookie(
- new SystemBlock(),
- true
- ) );
- }
-
/**
* @dataProvider provideShouldTrackBlockWithCookie
*/
diff --git a/tests/phpunit/includes/block/DatabaseBlockTest.php b/tests/phpunit/includes/block/DatabaseBlockTest.php
index f9d7924b134d..c66e753261be 100644
--- a/tests/phpunit/includes/block/DatabaseBlockTest.php
+++ b/tests/phpunit/includes/block/DatabaseBlockTest.php
@@ -735,12 +735,11 @@ class DatabaseBlockTest extends MediaWikiLangTestCase {
$this->assertFalse( $result );
// Ensure that there are no restrictions where the blockId is 0.
- $count = $this->db->selectRowCount(
- 'ipblocks_restrictions',
- '*',
- [ 'ir_ipb_id' => 0 ],
- __METHOD__
- );
+ $count = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'ipblocks_restrictions' )
+ ->where( [ 'ir_ipb_id' => 0 ] )
+ ->caller( __METHOD__ )->fetchRowCount();
$this->assertSame( 0, $count );
$blockStore->deleteBlock( $block );
diff --git a/tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php b/tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php
index 46fea1d40b1e..01f417e85e52 100644
--- a/tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php
+++ b/tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php
@@ -73,7 +73,11 @@ class LinksDeletionUpdateTest extends MediaWikiLangTestCase {
'templatelinks' => 'tl_from',
];
foreach ( $tables as $table => $fromField ) {
- $res = $this->db->select( $table, [ 1 ], [ $fromField => $id ], __METHOD__ );
+ $res = $this->db->newSelectQueryBuilder()
+ ->select( [ 1 ] )
+ ->from( $table )
+ ->where( [ $fromField => $id ] )
+ ->caller( __METHOD__ )->fetchResultSet();
$this->assertSame( 1, $res->numRows(), "Number of rows in table $table" );
}
@@ -84,7 +88,11 @@ class LinksDeletionUpdateTest extends MediaWikiLangTestCase {
$linksDeletionUpdate->doUpdate();
foreach ( $tables as $table => $fromField ) {
- $res = $this->db->select( $table, [ 1 ], [ $fromField => $id ], __METHOD__ );
+ $res = $this->db->newSelectQueryBuilder()
+ ->select( [ 1 ] )
+ ->from( $table )
+ ->where( [ $fromField => $id ] )
+ ->caller( __METHOD__ )->fetchResultSet();
$this->assertSame( 0, $res->numRows(), "Number of rows in table $table" );
}
}
diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
index 4d043a9dfcac..2c8a7725fe44 100644
--- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php
+++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
@@ -962,8 +962,12 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
$file->load();
$file->maybeUpgradeRow();
- $metadata = $dbw->decodeBlob( $dbw->selectField( 'image', 'img_metadata',
- [ 'img_name' => 'Test.pdf' ], __METHOD__ ) );
+ $metadata = $dbw->decodeBlob( $dbw->newSelectQueryBuilder()
+ ->select( 'img_metadata' )
+ ->from( 'image' )
+ ->where( [ 'img_name' => 'Test.pdf' ] )
+ ->caller( __METHOD__ )->fetchField()
+ );
$this->assertStringMatchesFormat( $expected, $metadata );
}
@@ -1016,8 +1020,12 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
$file = new LocalFile( $title, $repo );
$file->load();
$file->maybeUpgradeRow();
- $metadata = $dbw->decodeBlob( $dbw->selectField( 'image', 'img_metadata',
- [ 'img_name' => 'Png-native-test.png' ] ) );
+ $metadata = $dbw->decodeBlob( $dbw->newSelectQueryBuilder()
+ ->select( 'img_metadata' )
+ ->from( 'image' )
+ ->where( [ 'img_name' => 'Png-native-test.png' ] )
+ ->fetchField()
+ );
// Just confirm that it looks like JSON with real metadata
$this->assertStringStartsWith( '{"data":{"frameCount":0,', $metadata );
diff --git a/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php b/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
index 9842ea39ae09..95051731313a 100644
--- a/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
+++ b/tests/phpunit/includes/jobqueue/jobs/ClearUserWatchlistJobTest.php
@@ -73,12 +73,11 @@ class ClearUserWatchlistJobTest extends MediaWikiIntegrationTestCase {
$watchedItemStore->addWatch( $user, new TitleValue( 0, __METHOD__ . 'has expiry' ), '1 week' );
// Get the IDs of these items.
- $itemIds = $this->db->selectFieldValues(
- [ 'watchlist' ],
- 'wl_id',
- [ 'wl_user' => $user->getId() ],
- __METHOD__
- );
+ $itemIds = $this->db->newSelectQueryBuilder()
+ ->select( 'wl_id' )
+ ->from( 'watchlist' )
+ ->where( [ 'wl_user' => $user->getId() ] )
+ ->caller( __METHOD__ )->fetchFieldValues();
// Clear the watchlist by running the job.
$job = new ClearUserWatchlistJob( [
@@ -89,12 +88,11 @@ class ClearUserWatchlistJobTest extends MediaWikiIntegrationTestCase {
$this->runJobs( [ 'complete' => false ], [ 'maxJobs' => 1 ] );
// Confirm that there are now no expiry records.
- $watchedCount = $this->db->selectRowCount(
- 'watchlist_expiry',
- '*',
- [ 'we_item' => $itemIds ],
- __METHOD__
- );
+ $watchedCount = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'watchlist_expiry' )
+ ->where( [ 'we_item' => $itemIds ] )
+ ->caller( __METHOD__ )->fetchRowCount();
$this->assertSame( 0, $watchedCount );
}
}
diff --git a/tests/phpunit/includes/page/PageStoreTest.php b/tests/phpunit/includes/page/PageStoreTest.php
index 5c6a00711fe6..4eb818831661 100644
--- a/tests/phpunit/includes/page/PageStoreTest.php
+++ b/tests/phpunit/includes/page/PageStoreTest.php
@@ -651,11 +651,11 @@ class PageStoreTest extends MediaWikiIntegrationTestCase {
$existingPage = $this->getExistingTestPage();
$pageStore = $this->getPageStore();
- $row = $this->db->selectRow(
- 'page',
- $pageStore->getSelectFields(),
- [ 'page_id' => $existingPage->getId() ]
- );
+ $row = $this->db->newSelectQueryBuilder()
+ ->select( $pageStore->getSelectFields() )
+ ->from( 'page' )
+ ->where( [ 'page_id' => $existingPage->getId() ] )
+ ->fetchRow();
$rec = $pageStore->newPageRecordFromRow( $row );
$this->assertSamePage( $existingPage, $rec );
diff --git a/tests/phpunit/includes/page/WikiPageDbTest.php b/tests/phpunit/includes/page/WikiPageDbTest.php
index d0d7ab5fbf3f..b89419826355 100644
--- a/tests/phpunit/includes/page/WikiPageDbTest.php
+++ b/tests/phpunit/includes/page/WikiPageDbTest.php
@@ -435,14 +435,11 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
// as long as no garbage is written to the database.
}
- $row = $this->db->selectRow(
- 'page',
- '*',
- [
- 'page_namespace' => $title->getNamespace(),
- 'page_title' => $title->getDBkey()
- ]
- );
+ $row = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'page' )
+ ->where( [ 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() ] )
+ ->fetchRow();
$this->assertFalse( $row );
}
@@ -1547,11 +1544,19 @@ more stuff
] ] );
// Check the page_random field has been filled
- $pageRandom = $this->db->selectField( 'page', 'page_random', $condition );
+ $pageRandom = $this->db->newSelectQueryBuilder()
+ ->select( 'page_random' )
+ ->from( 'page' )
+ ->where( $condition )
+ ->fetchField();
$this->assertTrue( (float)$pageRandom < 1 && (float)$pageRandom > 0 );
// Assert the touched timestamp in the DB is roughly when we inserted the page
- $pageTouched = $this->db->selectField( 'page', 'page_touched', $condition );
+ $pageTouched = $this->db->newSelectQueryBuilder()
+ ->select( 'page_touched' )
+ ->from( 'page' )
+ ->where( $condition )
+ ->fetchField();
$this->assertTrue(
wfTimestamp( TS_UNIX, $startTimeStamp )
<= wfTimestamp( TS_UNIX, $pageTouched )
@@ -2037,7 +2042,11 @@ more stuff
public function testGetTouched() {
$page = $this->createPage( __METHOD__, 'whatever' );
- $touched = $this->db->selectField( 'page', 'page_touched', [ 'page_id' => $page->getId() ] );
+ $touched = $this->db->newSelectQueryBuilder()
+ ->select( 'page_touched' )
+ ->from( 'page' )
+ ->where( [ 'page_id' => $page->getId() ] )
+ ->fetchField();
$touched = MWTimestamp::convert( TS_MW, $touched );
// Internal cache of the touched time was set after the page was created
diff --git a/tests/phpunit/includes/session/UserInfoTest.php b/tests/phpunit/includes/session/UserInfoTest.php
index ef786b85a7d5..3138b6a4ce44 100644
--- a/tests/phpunit/includes/session/UserInfoTest.php
+++ b/tests/phpunit/includes/session/UserInfoTest.php
@@ -8,7 +8,7 @@ use MediaWikiIntegrationTestCase;
/**
* @group Session
* @group Database
- * @covers MediaWiki\Session\UserInfo
+ * @covers \MediaWiki\Session\UserInfo
*/
class UserInfoTest extends MediaWikiIntegrationTestCase {
@@ -26,7 +26,10 @@ class UserInfoTest extends MediaWikiIntegrationTestCase {
}
public function testNewFromId() {
- $id = wfGetDB( DB_PRIMARY )->selectField( 'user', 'MAX(user_id)' ) + 1;
+ $id = $this->getDb()->newSelectQueryBuilder()
+ ->select( 'MAX(user_id)' )
+ ->from( 'user' )
+ ->fetchField() + 1;
try {
UserInfo::newFromId( $id );
$this->fail( 'Expected exception not thrown' );
diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php
index f4fe19d93a08..7ae7860a32f6 100644
--- a/tests/phpunit/includes/specials/SpecialBlockTest.php
+++ b/tests/phpunit/includes/specials/SpecialBlockTest.php
@@ -389,12 +389,11 @@ class SpecialBlockTest extends SpecialPageTestBase {
$this->assertSame( [], $block->getRestrictions() );
// Ensure that there are no restrictions where the blockId is 0.
- $count = $this->db->selectRowCount(
- 'ipblocks_restrictions',
- '*',
- [ 'ir_ipb_id' => 0 ],
- __METHOD__
- );
+ $count = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'ipblocks_restrictions' )
+ ->where( [ 'ir_ipb_id' => 0 ] )
+ ->caller( __METHOD__ )->fetchRowCount();
$this->assertSame( 0, $count );
}
diff --git a/tests/phpunit/includes/title/TitleTest.php b/tests/phpunit/includes/title/TitleTest.php
index 529af4ee23fd..bb4f7c923ddc 100644
--- a/tests/phpunit/includes/title/TitleTest.php
+++ b/tests/phpunit/includes/title/TitleTest.php
@@ -761,12 +761,10 @@ class TitleTest extends MediaWikiIntegrationTestCase {
*/
public function testNewFromMissingId() {
// Testing return of null for an id that does not exist
- $maxPageId = (int)$this->db->selectField(
- 'page',
- 'max(page_id)',
- '',
- __METHOD__
- );
+ $maxPageId = (int)$this->db->newSelectQueryBuilder()
+ ->select( 'max(page_id)' )
+ ->from( 'page' )
+ ->caller( __METHOD__ )->fetchField();
$res = Title::newFromID( $maxPageId + 1 );
$this->assertNull( $res, 'newFromID returns null for missing ids' );
}
diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php
index 3d1c0f4442bb..5eb3cc719c02 100644
--- a/tests/phpunit/includes/user/UserTest.php
+++ b/tests/phpunit/includes/user/UserTest.php
@@ -709,9 +709,11 @@ class UserTest extends MediaWikiIntegrationTestCase {
$user->saveSettings();
$this->assertSame(
$user->getName(),
- $this->db->selectField(
- 'actor', 'actor_name', [ 'actor_id' => $user->getActorId() ], __METHOD__
- ),
+ $this->db->newSelectQueryBuilder()
+ ->select( 'actor_name' )
+ ->from( 'actor' )
+ ->where( [ 'actor_id' => $user->getActorId() ] )
+ ->caller( __METHOD__ )->fetchField(),
'User::saveSettings updates actor table for name change'
);
diff --git a/tests/phpunit/includes/watcheditem/WatchedItemStoreIntegrationTest.php b/tests/phpunit/includes/watcheditem/WatchedItemStoreIntegrationTest.php
index 6caca58293d3..7112c7fcd37c 100644
--- a/tests/phpunit/includes/watcheditem/WatchedItemStoreIntegrationTest.php
+++ b/tests/phpunit/includes/watcheditem/WatchedItemStoreIntegrationTest.php
@@ -422,20 +422,29 @@ class WatchedItemStoreIntegrationTest extends MediaWikiIntegrationTestCase {
[ 'we_item' => '100001', 'we_expiry' => $this->db->timestamp( '30300101000000' ) ],
];
$this->db->insert( 'watchlist_expiry', $orphanRows, __METHOD__ );
- $initialRowCount = $this->db->selectRowCount( 'watchlist_expiry', '*', [], __METHOD__ );
+ $initialRowCount = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'watchlist_expiry' )
+ ->caller( __METHOD__ )->fetchRowCount();
// Make sure the orphans aren't removed if it's not requested.
$store->removeExpired( 10, false );
$this->assertSame(
$initialRowCount,
- $this->db->selectRowCount( 'watchlist_expiry', '*', [], __METHOD__ )
+ $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'watchlist_expiry' )
+ ->caller( __METHOD__ )->fetchRowCount()
);
// Make sure they are removed when requested.
$store->removeExpired( 10, true );
$this->assertSame(
$initialRowCount - 2,
- $this->db->selectRowCount( 'watchlist_expiry', '*', [], __METHOD__ )
+ $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'watchlist_expiry' )
+ ->caller( __METHOD__ )->fetchRowCount()
);
}
}