aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/db
diff options
context:
space:
mode:
authorTim Starling <tstarling@wikimedia.org>2023-12-01 14:35:11 +1100
committerTim Starling <tstarling@wikimedia.org>2024-01-12 09:33:05 +1100
commit551ec29ea676cc73cd127b2f9cfc9bedcfc9fdc5 (patch)
tree659bf574c34a7d3c36776d4fe885f435df910034 /tests/phpunit/integration/includes/db
parent2a31e12e3fb5e0d71b8edeb37ddb5d20efb4e894 (diff)
downloadmediawikicore-551ec29ea676cc73cd127b2f9cfc9bedcfc9fdc5.tar.gz
mediawikicore-551ec29ea676cc73cd127b2f9cfc9bedcfc9fdc5.zip
Check warnings from INSERT during tests
INSERT IGNORE when inserting NULL into a non-nullable field will succeed with a warning on MySQL but fail on PostgreSQL. In any case, it's probably harmful and unintended. But to check the error code of MySQL warnings, you need to query the server with SHOW WARNINGS, so there is a performance cost. So, add a configuration variable which, when enabled, checks warnings after INSERT to see if there were any null type constraint errors. Set it to true in DevelopmentSettings.php and TestSetup.php. Change-Id: I5e47e2d3cc7e0f804036e11b512b1e3b76804432
Diffstat (limited to 'tests/phpunit/integration/includes/db')
-rw-r--r--tests/phpunit/integration/includes/db/DatabaseMysqlTest.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php b/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php
index c61f42f7b9fe..e9e28d6a5be4 100644
--- a/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php
+++ b/tests/phpunit/integration/includes/db/DatabaseMysqlTest.php
@@ -543,4 +543,18 @@ class DatabaseMysqlTest extends \MediaWikiIntegrationTestCase {
$this->conn->query( "DROP TEMPORARY TABLE IF EXISTS `$wgDBname`.`tmp_dst_tbl`" );
}
+
+ /**
+ * Insert a null value into a field that is not nullable using INSERT IGNORE
+ *
+ * @covers \Wikimedia\Rdbms\DatabaseMySQL::checkInsertWarnings
+ */
+ public function testInsertIgnoreNull() {
+ $this->expectException( DBQueryError::class );
+ $this->conn->newInsertQueryBuilder()
+ ->insertInto( 'log_search' )
+ ->ignore()
+ ->row( [ 'ls_field' => 'test', 'ls_value' => null, 'ls_log_id' => 1 ] )
+ ->execute();
+ }
}