From e7aa5b6b2bdee8f84aca62050e5e33f52c15bbfb Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 16 Mar 2021 15:08:06 +1300 Subject: [PATCH] Tighten mysql mode in test environment At least one test fails (and the corresponding bug appears on our live site) with the mysql modes IGNORE_SPACE, ERROR_FOR_DIVISION_BY_ZERO and STRICT_TRANS (I think any 2 of the above is OK) Let's throw it at jenkins & see how many friends it has --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index b063711737..9fd3369ab6 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -372,12 +372,13 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $this->renameLabels(); $this->_sethtmlGlobals(); + $this->ensureMySQLMode(['IGNORE_SPACE', 'ERROR_FOR_DIVISION_BY_ZERO', 'STRICT_TRANS_TABLES']); } /** * Read everything from the datasets directory and insert into the db. */ - public function loadAllFixtures() { + public function loadAllFixtures(): void { $fixturesDir = __DIR__ . '/../../fixtures'; CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 0;"); @@ -3790,4 +3791,15 @@ WHERE a1.is_primary = 0 ')); } + /** + * Ensure the specified mysql mode/s are activated. + * + * @param array $modes + */ + protected function ensureMySQLMode(array $modes): void { + $currentModes = array_fill_keys(CRM_Utils_SQL::getSqlModes(), 1); + $currentModes = array_merge($currentModes, array_fill_keys($modes, 1)); + CRM_Core_DAO::executeQuery("SET GLOBAL sql_mode = '" . implode(',', array_keys($currentModes)) . "'"); + } + } -- 2.25.1