aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUmherirrender <umherirrender_de.wp@web.de>2024-05-02 22:22:10 +0200
committerUmherirrender <umherirrender_de.wp@web.de>2024-05-02 23:42:08 +0200
commit6f94bde337a930362a3df8de74f1318a515a716f (patch)
treed8c21e7ba60fbd64b0f8a22e93a74ef72cf1de79
parentb66a1bf1dfc9c92c3bddba9b9aeac7f1ad94aa1a (diff)
downloadmediawikicore-6f94bde337a930362a3df8de74f1318a515a716f.tar.gz
mediawikicore-6f94bde337a930362a3df8de74f1318a515a716f.zip
tests: Migrate to IReadableDatabase::newSelectQueryBuilder
Bug: T344971 Change-Id: Ic6940fcc06225069a0c3618c22a0e62942e5dd88
-rw-r--r--tests/phpunit/MediaWikiIntegrationTestCase.php28
-rw-r--r--tests/phpunit/includes/CommentStore/CommentStoreTest.php14
-rw-r--r--tests/phpunit/includes/Revision/RevisionStoreDbTest.php78
-rw-r--r--tests/phpunit/includes/Storage/PageUpdaterTest.php13
-rw-r--r--tests/phpunit/includes/block/DatabaseBlockTest.php15
-rw-r--r--tests/phpunit/includes/user/ActorMigrationTest.php28
-rw-r--r--tests/phpunit/integration/includes/block/DatabaseBlockStoreTest.php21
7 files changed, 87 insertions, 110 deletions
diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php
index 812973c0571d..3e39b92515d4 100644
--- a/tests/phpunit/MediaWikiIntegrationTestCase.php
+++ b/tests/phpunit/MediaWikiIntegrationTestCase.php
@@ -2209,7 +2209,11 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
$tables = self::listOriginalTables( $source );
foreach ( $tables as $table ) {
- $res = $source->select( $table, '*', [], __METHOD__ );
+ $res = $source->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( $table )
+ ->caller( __METHOD__ )
+ ->fetchResultSet();
if ( !$res->numRows() ) {
continue;
}
@@ -2288,16 +2292,18 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
}
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
-
- $res = $dbr->select(
- $table,
- $fields,
- $condition,
- wfGetCaller(),
- $options + [ 'ORDER BY' => $fields ],
- $join_conds
- );
- $this->assertNotFalse( $res, "query failed: " . $dbr->lastError() );
+ $tables = is_array( $table ) ? $table : [ $table ];
+ $conds = $condition === '' || $condition === '*' ? [] : $condition;
+
+ $res = $dbr->newSelectQueryBuilder()
+ ->tables( $tables )
+ ->fields( $fields )
+ ->conds( $conds )
+ ->caller( wfGetCaller() )
+ ->options( $options )
+ ->orderBy( $fields )
+ ->joinConds( $join_conds )
+ ->fetchResultSet();
$i = 0;
diff --git a/tests/phpunit/includes/CommentStore/CommentStoreTest.php b/tests/phpunit/includes/CommentStore/CommentStoreTest.php
index f19e2e96ed6d..3962e9bae8bb 100644
--- a/tests/phpunit/includes/CommentStore/CommentStoreTest.php
+++ b/tests/phpunit/includes/CommentStore/CommentStoreTest.php
@@ -148,14 +148,12 @@ class CommentStoreTest extends MediaWikiLangTestCase {
->caller( __METHOD__ )->fetchRow();
$queryInfo = $rstore->getJoin( $key );
- $joinRow = $this->db->selectRow(
- [ $table ] + $queryInfo['tables'],
- $queryInfo['fields'],
- [ $pk => $id ],
- __METHOD__,
- [],
- $queryInfo['joins']
- );
+ $joinRow = $this->db->newSelectQueryBuilder()
+ ->queryInfo( $queryInfo )
+ ->from( $table )
+ ->where( [ $pk => $id ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$this->assertComment(
$expect,
diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
index 9beef152aba3..03eab6fe986f 100644
--- a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
+++ b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
@@ -1142,24 +1142,18 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$store = $this->getServiceContainer()->getRevisionStore();
$info = $store->getQueryInfo();
- $row = $this->getDb()->selectRow(
- $info['tables'],
- $info['fields'],
- [ 'rev_id' => $revRecord->getId() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $row = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'rev_id' => $revRecord->getId() ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$info = $store->getSlotsQueryInfo( [ 'content' ] );
- $slotRows = $this->getDb()->select(
- $info['tables'],
- $info['fields'],
- [ 'slot_revision_id' => $revRecord->getId() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $slotRows = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'slot_revision_id' => $revRecord->getId() ] )
+ ->caller( __METHOD__ )
+ ->fetchResultSet();
$storeRecord = $store->newRevisionFromRowAndSlots(
$row,
@@ -1187,14 +1181,11 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$store = $this->getServiceContainer()->getRevisionStore();
$info = $store->getQueryInfo();
- $row = $this->getDb()->selectRow(
- $info['tables'],
- $info['fields'],
- [ 'rev_id' => $revRecord->getId() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $row = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'rev_id' => $revRecord->getId() ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$storeRecord = $store->newRevisionFromRow(
$row,
0,
@@ -1291,14 +1282,11 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$this->assertIsObject( $res, 'query failed' );
$info = $store->getSlotsQueryInfo( [ 'content' ] );
- $slotRows = $this->getDb()->select(
- $info['tables'],
- $info['fields'],
- [ 'slot_revision_id' => $orig->getId() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $slotRows = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'slot_revision_id' => $orig->getId() ] )
+ ->caller( __METHOD__ )
+ ->fetchResultSet();
$row = $res->fetchObject();
$res->free();
@@ -1579,14 +1567,11 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$page = $this->getExistingTestPage();
$info = $store->getQueryInfo();
- $row = $this->getDb()->selectRow(
- $info['tables'],
- $info['fields'],
- [ 'rev_page' => $page->getId(), 'rev_id' => $page->getLatest() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $row = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'rev_page' => $page->getId(), 'rev_id' => $page->getLatest() ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$record = $store->newRevisionFromRow( $row );
@@ -1616,14 +1601,11 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
->getRevisionStore( $wikiId );
$info = $store->getQueryInfo();
- $row = $this->getDb()->selectRow(
- $info['tables'],
- $info['fields'],
- [ 'rev_page' => $page->getId(), 'rev_id' => $page->getLatest() ],
- __METHOD__,
- [],
- $info['joins']
- );
+ $row = $this->getDb()->newSelectQueryBuilder()
+ ->queryInfo( $info )
+ ->where( [ 'rev_page' => $page->getId(), 'rev_id' => $page->getLatest() ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$record = $store->newRevisionFromRow( $row );
diff --git a/tests/phpunit/includes/Storage/PageUpdaterTest.php b/tests/phpunit/includes/Storage/PageUpdaterTest.php
index 1ea8f1937335..7a10da47ab15 100644
--- a/tests/phpunit/includes/Storage/PageUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/PageUpdaterTest.php
@@ -64,14 +64,11 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
*/
private function getRecentChangeFor( $revId ) {
$qi = RecentChange::getQueryInfo();
- $row = $this->db->selectRow(
- $qi['tables'],
- $qi['fields'],
- [ 'rc_this_oldid' => $revId ],
- __METHOD__,
- [],
- $qi['joins']
- );
+ $row = $this->db->newSelectQueryBuilder()
+ ->queryInfo( $qi )
+ ->where( [ 'rc_this_oldid' => $revId ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
return $row ? RecentChange::newFromRow( $row ) : null;
}
diff --git a/tests/phpunit/includes/block/DatabaseBlockTest.php b/tests/phpunit/includes/block/DatabaseBlockTest.php
index ce2a49e2357b..d5ec73570722 100644
--- a/tests/phpunit/includes/block/DatabaseBlockTest.php
+++ b/tests/phpunit/includes/block/DatabaseBlockTest.php
@@ -419,16 +419,13 @@ class DatabaseBlockTest extends MediaWikiLangTestCase {
$blockStore->insertBlock( $block );
$blockQuery = DatabaseBlock::getQueryInfo();
- $row = $this->db->select(
- $blockQuery['tables'],
- $blockQuery['fields'],
- [
+ $row = $this->db->newSelectQueryBuilder()
+ ->queryInfo( $blockQuery )
+ ->where( [
'ipb_id' => $block->getId(),
- ],
- __METHOD__,
- [],
- $blockQuery['joins']
- )->fetchObject();
+ ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$block = DatabaseBlock::newFromRow( $row );
$this->assertInstanceOf( DatabaseBlock::class, $block );
diff --git a/tests/phpunit/includes/user/ActorMigrationTest.php b/tests/phpunit/includes/user/ActorMigrationTest.php
index 7ac6f3db0d8e..e845963d7ec9 100644
--- a/tests/phpunit/includes/user/ActorMigrationTest.php
+++ b/tests/phpunit/includes/user/ActorMigrationTest.php
@@ -465,14 +465,12 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
$r = $this->getMigration( $readStage );
$queryInfo = $r->getJoin( $key );
- $row = $this->db->selectRow(
- [ $table ] + $queryInfo['tables'],
- $queryInfo['fields'],
- [ $pk => $id ],
- __METHOD__,
- [],
- $queryInfo['joins']
- );
+ $row = $this->db->newSelectQueryBuilder()
+ ->queryInfo( $queryInfo )
+ ->from( $table )
+ ->where( [ $pk => $id ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$this->assertSame( $user->getId(), (int)$row->$key,
"w={$stageNames[$writeStage]}, r={$stageNames[$readStage]}, id" );
@@ -515,14 +513,12 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
->execute();
$qi = $m->getJoin( 'am1_user' );
- $row = $this->db->selectRow(
- [ 'actormigration1' ] + $qi['tables'],
- $qi['fields'],
- [ 'am1_id' => $id ],
- __METHOD__,
- [],
- $qi['joins']
- );
+ $row = $this->db->newSelectQueryBuilder()
+ ->queryInfo( $qi )
+ ->from( 'actormigration1' )
+ ->where( [ 'am1_id' => $id ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$this->assertSame( $user->getId(), (int)$row->am1_user );
$this->assertSame( $user->getName(), $row->am1_user_text );
$this->assertSame(
diff --git a/tests/phpunit/integration/includes/block/DatabaseBlockStoreTest.php b/tests/phpunit/integration/includes/block/DatabaseBlockStoreTest.php
index 603ecb844f23..9616654d6abf 100644
--- a/tests/phpunit/integration/includes/block/DatabaseBlockStoreTest.php
+++ b/tests/phpunit/integration/includes/block/DatabaseBlockStoreTest.php
@@ -188,12 +188,12 @@ class DatabaseBlockStoreTest extends MediaWikiIntegrationTestCase {
public function testNewFromID_missing() {
$store = $this->getStore();
$missingBlockId = 9998;
- $dbRow = $this->db->selectRow(
- 'ipblocks',
- '*',
- [ 'ipb_id' => $missingBlockId ],
- __METHOD__
- );
+ $dbRow = $this->db->newSelectQueryBuilder()
+ ->select( '*' )
+ ->from( 'ipblocks' )
+ ->where( [ 'ipb_id' => $missingBlockId ] )
+ ->caller( __METHOD__ )
+ ->fetchRow();
$this->assertFalse(
$dbRow,
"Sanity check: make sure there is no block with id $missingBlockId"
@@ -657,10 +657,11 @@ class DatabaseBlockStoreTest extends MediaWikiIntegrationTestCase {
$this->sysop = $this->getTestSysop()->getUser();
// Get a comment ID. One was added in addDBDataOnce.
- $commentId = $this->db->select(
- 'comment',
- 'comment_id'
- )->fetchObject()->comment_id;
+ $commentId = $this->db->newSelectQueryBuilder()
+ ->select( 'comment_id' )
+ ->from( 'comment' )
+ ->caller( __METHOD__ )
+ ->fetchField();
$commonBlockData = [
'ipb_by_actor' => $this->sysop->getActorId(),