aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
authorTim Starling <tstarling@wikimedia.org>2023-09-08 10:06:59 +1000
committerTim Starling <tstarling@wikimedia.org>2023-09-08 10:16:08 +1000
commit95bd40b25cd6eea81c39d0e88170a214520f7c77 (patch)
tree5eb0426f77cbf2bde662dd2646dc55dfc79424ba /tests/phpunit
parent7bbc107f164a3ddc20641471b08380794559e53a (diff)
downloadmediawikicore-95bd40b25cd6eea81c39d0e88170a214520f7c77.tar.gz
mediawikicore-95bd40b25cd6eea81c39d0e88170a214520f7c77.zip
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained builder calls look as much like SQL as possible, so that developers could leverage their knowledge of SQL to understand what the query builder is doing. That's why SelectQueryBuilder::select() takes a list of fields, and by the same principle, it makes sense for UpdateQueryBuilder::update() to take a table. However with "insert" and "delete", the SQL designers chose to add prepositions "into" and "from", and I think it makes sense to follow that here. In terms of natural language, we update a table, but we don't delete a table, or insert a table. We delete rows from a table, or insert rows into a table. The table is not the object of the verb. So, add insertInto() as an alias for insert(), and add deleteFrom() as an alias for delete(). Use the new methods in MW core callers where PHPStorm knows the type. Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php2
-rw-r--r--tests/phpunit/includes/changetags/ChangeTagsTest.php4
-rw-r--r--tests/phpunit/includes/filerepo/file/LocalFileTest.php2
-rw-r--r--tests/phpunit/includes/interwiki/InterwikiTest.php2
-rw-r--r--tests/phpunit/includes/session/BotPasswordSessionProviderTest.php2
-rw-r--r--tests/phpunit/includes/user/BotPasswordTest.php2
-rw-r--r--tests/phpunit/unit/includes/libs/rdbms/querybuilder/DeleteQueryBuilderTest.php6
-rw-r--r--tests/phpunit/unit/includes/libs/rdbms/querybuilder/InsertQueryBuilderTest.php18
8 files changed, 19 insertions, 19 deletions
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 72dad35437ea..4f4fa91baa0c 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -858,7 +858,7 @@ class ApiEditPageTest extends ApiTestCase {
// Make the middle revision disappear
$dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
- ->delete( 'revision' )
+ ->deleteFrom( 'revision' )
->where( [ 'rev_id' => $revId2 ] )
->caller( __METHOD__ )->execute();
$dbw->newUpdateQueryBuilder()
diff --git a/tests/phpunit/includes/changetags/ChangeTagsTest.php b/tests/phpunit/includes/changetags/ChangeTagsTest.php
index cd367f502deb..f2c1593825ec 100644
--- a/tests/phpunit/includes/changetags/ChangeTagsTest.php
+++ b/tests/phpunit/includes/changetags/ChangeTagsTest.php
@@ -32,11 +32,11 @@ class ChangeTagsTest extends MediaWikiIntegrationTestCase {
private function emptyChangeTagsTables() {
$dbw = wfGetDB( DB_PRIMARY );
$dbw->newDeleteQueryBuilder()
- ->delete( 'change_tag' )
+ ->deleteFrom( 'change_tag' )
->where( ISQLPlatform::ALL_ROWS )
->execute();
$dbw->newDeleteQueryBuilder()
- ->delete( 'change_tag_def' )
+ ->deleteFrom( 'change_tag_def' )
->where( ISQLPlatform::ALL_ROWS )
->execute();
}
diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
index 2f1d68cefa43..4d043a9dfcac 100644
--- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php
+++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
@@ -654,7 +654,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
// Make sure we were actually hitting the WAN cache
$dbw->newDeleteQueryBuilder()
- ->delete( 'image' )
+ ->deleteFrom( 'image' )
->where( [ 'img_name' => 'Random-11m.png' ] )
->caller( __METHOD__ )->execute();
$file->invalidateCache();
diff --git a/tests/phpunit/includes/interwiki/InterwikiTest.php b/tests/phpunit/includes/interwiki/InterwikiTest.php
index 916b3eafd791..8c2e6733abda 100644
--- a/tests/phpunit/includes/interwiki/InterwikiTest.php
+++ b/tests/phpunit/includes/interwiki/InterwikiTest.php
@@ -45,7 +45,7 @@ class InterwikiTest extends MediaWikiIntegrationTestCase {
private function populateDB( $iwrows ) {
$dbw = wfGetDB( DB_PRIMARY );
$dbw->newDeleteQueryBuilder()
- ->delete( 'interwiki' )
+ ->deleteFrom( 'interwiki' )
->where( ISQLPlatform::ALL_ROWS )
->caller( __METHOD__ )->execute();
$dbw->insert( 'interwiki', array_values( $iwrows ), __METHOD__ );
diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
index 246721c8b8a9..7ac42015ee42 100644
--- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
+++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
@@ -82,7 +82,7 @@ class BotPasswordSessionProviderTest extends MediaWikiIntegrationTestCase {
$dbw = wfGetDB( DB_PRIMARY );
$dbw->newDeleteQueryBuilder()
- ->delete( 'bot_passwords' )
+ ->deleteFrom( 'bot_passwords' )
->where( [ 'bp_user' => $userId, 'bp_app_id' => 'BotPasswordSessionProvider' ] )
->caller( __METHOD__ )->execute();
$dbw->insert(
diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php
index d2a8af4fb6bd..bbe64b01f2a6 100644
--- a/tests/phpunit/includes/user/BotPasswordTest.php
+++ b/tests/phpunit/includes/user/BotPasswordTest.php
@@ -65,7 +65,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
$dbw = wfGetDB( DB_PRIMARY );
$dbw->newDeleteQueryBuilder()
- ->delete( 'bot_passwords' )
+ ->deleteFrom( 'bot_passwords' )
->where( [ 'bp_user' => [ 42, 43 ], 'bp_app_id' => 'BotPassword' ] )
->caller( __METHOD__ )->execute();
$dbw->insert(
diff --git a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/DeleteQueryBuilderTest.php b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/DeleteQueryBuilderTest.php
index 7ee820d52278..191d6191bf7a 100644
--- a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/DeleteQueryBuilderTest.php
+++ b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/DeleteQueryBuilderTest.php
@@ -39,7 +39,7 @@ class DeleteQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testConflictingConds() {
$this->dqb
- ->delete( '1' )
+ ->deleteFrom( '1' )
->where( [ 'k' => 'v1' ] )
->andWhere( [ 'k' => 'v2' ] );
$this->assertSQL( 'DELETE FROM 1 WHERE k = \'v1\' AND (k = \'v2\')', __METHOD__ );
@@ -53,14 +53,14 @@ class DeleteQueryBuilderTest extends PHPUnit\Framework\TestCase {
}
public function testExecute() {
- $this->dqb->delete( 't' )->where( 'c' )->caller( __METHOD__ );
+ $this->dqb->deleteFrom( 't' )->where( 'c' )->caller( __METHOD__ );
$this->dqb->execute();
$this->assertEquals( 'DELETE FROM t WHERE (c)', $this->db->getLastSqls() );
}
public function testGetQueryInfo() {
$this->dqb
- ->delete( 't' )
+ ->deleteFrom( 't' )
->where( [ 'a' => 'b' ] );
$this->assertEquals(
[
diff --git a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/InsertQueryBuilderTest.php b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/InsertQueryBuilderTest.php
index cd1e1e4b5932..bb224916f578 100644
--- a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/InsertQueryBuilderTest.php
+++ b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/InsertQueryBuilderTest.php
@@ -27,14 +27,14 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testSimpleInsert() {
$this->iqb
- ->insert( 'a' )
+ ->insertInto( 'a' )
->row( [ 'f' => 'g', 'd' => 'l' ] );
$this->assertSQL( "INSERT INTO a (f,d) VALUES ('g','l')", __METHOD__ );
}
public function testIgnore() {
$this->iqb
- ->insert( 'a' )
+ ->insertInto( 'a' )
->ignore()
->row( [ 'f' => 'g', 'd' => 'l' ] );
$this->assertSQL( "INSERT IGNORE INTO a (f,d) VALUES ('g','l')", __METHOD__ );
@@ -42,7 +42,7 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testUpsert() {
$this->iqb
- ->insert( 'a' )
+ ->insertInto( 'a' )
->row( [ 'f' => 'g', 'd' => 'l' ] )
->onDuplicateKeyUpdate()
->uniqueIndexFields( [ 'd' ] )
@@ -55,7 +55,7 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testUpsertWithStringKey() {
$this->iqb
- ->insert( 'a' )
+ ->insertInto( 'a' )
->row( [ 'f' => 'g', 'd' => 'l' ] )
->onDuplicateKeyUpdate()
->uniqueIndexFields( 'd' )
@@ -68,7 +68,7 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testOption() {
$this->iqb
- ->insert( 't' )
+ ->insertInto( 't' )
->row( [ 'f' => 'g' ] )
->option( 'IGNORE' );
$this->assertSQL( "INSERT IGNORE INTO t (f) VALUES ('g')", __METHOD__ );
@@ -76,21 +76,21 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testOptions() {
$this->iqb
- ->insert( 't' )
+ ->insertInto( 't' )
->row( [ 'f' => 'g' ] )
->options( [ 'IGNORE' ] );
$this->assertSQL( "INSERT IGNORE INTO t (f) VALUES ('g')", __METHOD__ );
}
public function testExecute() {
- $this->iqb->insert( 't' )->rows( [ 'a' => 'b' ] )->caller( __METHOD__ );
+ $this->iqb->insertInto( 't' )->rows( [ 'a' => 'b' ] )->caller( __METHOD__ );
$this->iqb->execute();
$this->assertEquals( "INSERT INTO t (a) VALUES ('b')", $this->db->getLastSqls() );
}
public function testGetQueryInfo() {
$this->iqb
- ->insert( 't' )
+ ->insertInto( 't' )
->ignore()
->row( [ 'a' => 'b', 'd' => 'l' ] );
$this->assertEquals(
@@ -107,7 +107,7 @@ class InsertQueryBuilderTest extends PHPUnit\Framework\TestCase {
public function testGetQueryInfoUpsert() {
$this->iqb
- ->insert( 't' )
+ ->insertInto( 't' )
->row( [ 'f' => 'g', 'd' => 'l' ] )
->onDuplicateKeyUpdate()
->uniqueIndexFields( [ 'd' ] )