From f6cc33f13825396c027a2831246ae84aea922619 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 17 Feb 2023 17:18:07 +0100 Subject: [PATCH] Continued: - also check if root_base_path + relative path from parameter is a readable directory - applications/tests/tests/ is redudant here --- application/tests/class_ApplicationHelper.php | 3 --- framework/loader/class_ClassLoader.php | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/application/tests/class_ApplicationHelper.php b/application/tests/class_ApplicationHelper.php index 3d69f0fc..bb32d2e0 100644 --- a/application/tests/class_ApplicationHelper.php +++ b/application/tests/class_ApplicationHelper.php @@ -111,9 +111,6 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication // Register core tests ClassLoader::registerTestsPath('framework/main/tests'); - // Register own tests - ClassLoader::registerTestsPath('application/tests/tests'); - // Scan for them now ClassLoader::scanTestsClasses(); } diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index b31d21fb..07dfd842 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -342,17 +342,31 @@ final class ClassLoader { * * @param $relativePath Relative path to test classes * @return void - * @throws InvalidArgumentException If a parameter is invalid + * @throws InvalidArgumentException If a parameter is invalid or path not found */ public static function registerTestsPath (string $relativePath) { // Validate parameter + //* NOISY-DEBUG: */ printf('[%s:%d]: relativePath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $relativePath); if (empty($relativePath)) { // Should not be empty throw new InvalidArgumentException('Parameter "relativePath" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } + // Get real path from it + $fullQualifiedPath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path') . $relativePath; + + // Is it there? + //* NOISY-DEBUG: */ printf('[%s:%d]: fullQualifiedPath=%s' . PHP_EOL, __METHOD__, __LINE__, $fullQualifiedPath); + if (!is_dir($fullQualifiedPath)) { + // Not there + throw new InvalidArgumentException(sprintf('fullQualifiedPath=%s cannot be found', $fullQualifiedPath)); + } elseif (!is_readable($fullQualifiedPath)) { + // Not readable + throw new InvalidArgumentException(sprintf('fullQualifiedPath=%s is not readable', $fullQualifiedPath)); + } + // "Register" it - //* NOISY-DEBUG: */ printf('[%s:%d]: relativePath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $relativePath); + //* NOISY-DEBUG: */ printf('[%s:%d]: Adding relativePath=%s ...' . PHP_EOL, __METHOD__, __LINE__, $relativePath); self::$testPaths[$relativePath] = $relativePath; // Trace message -- 2.39.5