From ee7b8b95a389a533b0bcc541463d249d244f9356 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 7 Sep 2022 17:40:44 -0700 Subject: [PATCH] ClassScanner - Fix guard for preboot cache scenario I wanted to inspect how caches were getting setup during test-runs. So I applied this hack https://github.com/civicrm/civicrm-core/commit/02106e8693d13ced7a151834a4188ce8b16f6444 and then ran some tests, eg ``` CIVICRM_UF=UnitTests phpunit8 tests/phpunit/CRM/Case/WorkflowMessage/CaseActivityTest.php ``` You can see the change in the HitOrMiss report (displayed after the test). Before ====== ``` OK (3 tests, 38 assertions) HitOrMiss: { "ClassScanner::cache(index) => Early usage": 13, "ClassScanner::cache(structure) => New arraycache": 1 } ``` After ===== ``` OK (3 tests, 38 assertions) HitOrMiss: { "ClassScanner::cache(index) => create(...)": 1, "ClassScanner::cache(structure) => New arraycache": 2 } ``` --- Civi/Core/ClassScanner.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Civi/Core/ClassScanner.php b/Civi/Core/ClassScanner.php index 5002786749..5b318d056b 100644 --- a/Civi/Core/ClassScanner.php +++ b/Civi/Core/ClassScanner.php @@ -227,6 +227,7 @@ class ClassScanner { if (!isset(static::$caches[$name])) { switch ($name) { case 'index': + global $_DB_DATAOBJECT; if (empty($_DB_DATAOBJECT['CONFIG'])) { // Atypical example: You have a test with a @dataProvider that relies on ClassScanner. Runs before bot. return new \CRM_Utils_Cache_ArrayCache([]); -- 2.25.1