Civi\Test - Fix leak in active module-list for headless test
authorTim Otten <totten@civicrm.org>
Tue, 12 Jul 2022 02:00:59 +0000 (19:00 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 12 Jul 2022 03:25:00 +0000 (20:25 -0700)
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
Civi/Test.php
Civi/Test/Data.php
setup/plugins/installDatabase/BootstrapCivi.civi-setup.php
setup/plugins/installDatabase/Preboot.civi-setup.php

index bcb214d66e5e50f6846c9fb922ee001e75bf652b..383af493142c5ac0fa75b03b7a0deeca21e5bf39 100644 (file)
@@ -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 [];
     }
 
index 53c3df5ed1271fae59ebbeb397e678c44fe18dfe..dfa4d31c307c5d0bd08359c54502cd070275909f 100644 (file)
@@ -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']);
       }
     }
   }
index d2007f9e82a4065a597961de4e16dea3facd7037..87116adfeb67ac3a24b35415c8735669cd9a8983 100644 (file)
@@ -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]);
index 3592e35435cc5bd2c0f1fa40ff51e0dd4caa20bc..aabe7a6d890d43ab029d4b75093d8bf2df530170 100644 (file)
@@ -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);
 
index 116a50246739bd92123a695595b4107e9d89528e..d4851ef6f03a77711304843ef56d178611965cfd 100644 (file)
@@ -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);