Merge "Run database-using tests in MySQL STRICT mode"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 8 Sep 2016 04:20:45 +0000 (04:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 8 Sep 2016 04:20:45 +0000 (04:20 +0000)
tests/phpunit/MediaWikiTestCase.php

index 541ac11..50b3390 100644 (file)
@@ -477,6 +477,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        while ( $this->db->trxLevel() > 0 ) {
                                $this->db->rollback( __METHOD__, 'flush' );
                        }
+                       // Check for unsafe queries
+                       if ( $this->db->getType() === 'mysql' ) {
+                               $this->db->query( "SET sql_mode = 'STRICT_ALL_TABLES'" );
+                       }
                }
 
                DeferredUpdates::clearPendingUpdates();
@@ -495,7 +499,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        }
 
        protected function tearDown() {
-               global $wgRequest;
+               global $wgRequest, $wgSQLMode;
 
                $status = ob_get_status();
                if ( isset( $status['name'] ) &&
@@ -519,6 +523,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        while ( $this->db->trxLevel() > 0 ) {
                                $this->db->rollback( __METHOD__, 'flush' );
                        }
+                       if ( $this->db->getType() === 'mysql' ) {
+                               $this->db->query( "SET sql_mode = " . $this->db->addQuotes( $wgSQLMode ) );
+                       }
                }
 
                // Restore mw globals