From 3f0d4748e4a58a5d146a4632d6751584eb1bffd6 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 11 Jul 2022 19:00:59 -0700 Subject: [PATCH] Civi\Test - Fix leak in active module-list for headless test Steps to reproduce ------------------ Observed on a `dmaster` build while running these steps: * Run civix's `make-example.sh` * Or just run some subset involving a headless test, eg * civix generate:test --template=headless 'Civi\Civiexample\BarTest' * cv api extension.install key=$EXMODULE * phpunit8 ./tests/phpunit/Civi/Civiexample/BarTest.php Before ------ Fatal error: Uncaught Error: Class 'Civi\Api4\SearchSegment' not found in /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/search_kit/Civi/Api4/Service/Spec/Provider/SearchSegmentExtraFieldProvider.php on line 52 After ----- Test runs --- CRM/Core/I18n.php | 2 +- Civi/Test.php | 8 ++++---- Civi/Test/Data.php | 1 + .../plugins/installDatabase/BootstrapCivi.civi-setup.php | 2 +- setup/plugins/installDatabase/Preboot.civi-setup.php | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index bcb214d66e..383af49314 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -755,7 +755,7 @@ class CRM_Core_I18n { * Ex: $stringTable['enabled']['wildcardMatch']['foo'] = 'bar'; */ private function getWordReplacements() { - if (isset(Civi::$statics['testPreInstall'])) { + if (isset(Civi\Test::$statics['testPreInstall'])) { return []; } diff --git a/Civi/Test.php b/Civi/Test.php index 53c3df5ed1..dfa4d31c30 100644 --- a/Civi/Test.php +++ b/Civi/Test.php @@ -32,7 +32,7 @@ class Test { $conn = \Civi\Test::pdo(); $oldEscaper = \CRM_Core_I18n::$SQL_ESCAPER; - \Civi::$statics['testPreInstall'] = (\Civi::$statics['testPreInstall'] ?? 0) + 1; + \Civi\Test::$statics['testPreInstall'] = (\Civi\Test::$statics['testPreInstall'] ?? 0) + 1; try { \CRM_Core_I18n::$SQL_ESCAPER = function ($text) use ($conn) { return substr($conn->quote($text), 1, -1); @@ -40,9 +40,9 @@ class Test { return $callback(); } finally { \CRM_Core_I18n::$SQL_ESCAPER = $oldEscaper; - \Civi::$statics['testPreInstall']--; - if (\Civi::$statics['testPreInstall'] <= 0) { - unset(\Civi::$statics['testPreInstall']); + \Civi\Test::$statics['testPreInstall']--; + if (\Civi\Test::$statics['testPreInstall'] <= 0) { + unset(\Civi\Test::$statics['testPreInstall']); } } } diff --git a/Civi/Test/Data.php b/Civi/Test/Data.php index d2007f9e82..87116adfeb 100644 --- a/Civi/Test/Data.php +++ b/Civi/Test/Data.php @@ -42,6 +42,7 @@ class Data { unset($query, $query2, $query3); \Civi\Test::schema()->setStrict(TRUE); + \Civi::reset(); }); civicrm_api('setting', 'create', ['installed' => 1, 'domain_id' => 'all', 'version' => 3]); diff --git a/setup/plugins/installDatabase/BootstrapCivi.civi-setup.php b/setup/plugins/installDatabase/BootstrapCivi.civi-setup.php index 3592e35435..aabe7a6d89 100644 --- a/setup/plugins/installDatabase/BootstrapCivi.civi-setup.php +++ b/setup/plugins/installDatabase/BootstrapCivi.civi-setup.php @@ -22,7 +22,7 @@ if (!defined('CIVI_SETUP')) { \Civi\Setup::log()->info(sprintf('[%s] Bootstrap CiviCRM', basename(__FILE__))); \CRM_Core_I18n::$SQL_ESCAPER = NULL; - unset(\Civi::$statics['testPreInstall']); + unset(\Civi\Test::$statics['testPreInstall']); CRM_Core_Config::singleton(TRUE, TRUE); diff --git a/setup/plugins/installDatabase/Preboot.civi-setup.php b/setup/plugins/installDatabase/Preboot.civi-setup.php index 116a502467..d4851ef6f0 100644 --- a/setup/plugins/installDatabase/Preboot.civi-setup.php +++ b/setup/plugins/installDatabase/Preboot.civi-setup.php @@ -42,7 +42,7 @@ if (!defined('CIVI_SETUP')) { return $conn->escape_string($text); }; - \Civi::$statics['testPreInstall'] = 1; + \Civi\Test::$statics['testPreInstall'] = 1; CRM_Core_Config::singleton(FALSE, TRUE); -- 2.25.1