From 4cd22a3cf838dfa6a274a11a2f884e8f0b0c7e88 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 22 Aug 2022 20:24:41 -0700 Subject: [PATCH] UnitTests - Tighten class-scanning for `civicrm-core:tests/phpunit` This addresses a bug where: 1. Class-scanning of `civicrm-core:tests/phpunit/*` works with core-test-suites 2. Class-scanning of `civicrm-core:tests/phpunit/*` fails with civiimport test-suite. The difference is that core-tests setup class-loading for `civicrm-core:tests/phpunit/`; `civimport` understandably doesn't. Class-scanning is only viable if we regard the specific classes a loadable. This further tightens it: 1. Since core-test-suites can load `civicrm-core:tests/phpunit/*`, they will scan it 2. Since civiimport test-suite cannot load it, it will not scan it. --- Civi/Core/ClassScanner.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Civi/Core/ClassScanner.php b/Civi/Core/ClassScanner.php index d18f4ed113fa..500278674987 100644 --- a/Civi/Core/ClassScanner.php +++ b/Civi/Core/ClassScanner.php @@ -137,8 +137,10 @@ private static function scanCoreClasses(): array { static::scanFolders($classes, $civicrmRoot, 'Civi/WorkflowMessage', '\\'); static::scanFolders($classes, $civicrmRoot, 'CRM/*/Import', '_'); if (\CRM_Utils_Constant::value('CIVICRM_UF') === 'UnitTests') { - static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'CRM/*/WorkflowMessage', '_'); - static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'Civi/*/WorkflowMessage', '\\'); + if (strpos(get_include_path(), $civicrmRoot . 'tests/phpunit') !== FALSE) { + static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'CRM/*/WorkflowMessage', '_'); + static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'Civi/*/WorkflowMessage', '\\'); + } } $cache->set($cacheKey, $classes, static::TTL);