From e2c64b8dbc2e98f397b93152bab1f601df9c758e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 26 Feb 2017 17:07:55 +0100 Subject: [PATCH] Moving-session has started: - moved all files in application/tests/classes/ to framework/main/tests/ as they can (and should) be used by any application that wishes to run (unit) tests. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/tests/init.php | 9 + .../tests/{classes => tests}/.htaccess | 0 framework/loader/class_ClassLoader.php | 157 +++++++++++++----- .../main/tests}/.htaccess | 0 .../main/tests/commands}/.htaccess | 0 .../main/tests/commands/console}/.htaccess | 0 .../console/class_TestsConsoleMainCommand.php | 0 .../main/tests/controller}/.htaccess | 0 .../main/tests/controller/console}/.htaccess | 0 ...lass_TestsConsoleDefaultNewsController.php | 0 .../main/tests/filter}/.htaccess | 0 .../tests}/filter/class_BaseTestsFilter.php | 0 .../main/tests/filter/tests}/.htaccess | 0 .../main/tests}/filter/tests/class_Tests | 0 .../filter/tests/configuration}/.htaccess | 0 .../configuration/class_TestConfiguration | 0 .../tests/configuration/classes}/.htaccess | 0 ...TestConfigurationLoadableClassesFilter.php | 0 .../filter/tests/requirements}/.htaccess | 0 .../class_TestsPhpRequirementsFilter.php | 0 .../main/tests/resolver}/.htaccess | 0 .../main/tests/resolver/command}/.htaccess | 0 .../tests/resolver/command/console}/.htaccess | 0 .../class_TestsConsoleCommandResolver.php | 0 .../main/tests/resolver/controller/.htaccess | 1 + .../class_TestsConsoleControllerResolver.php | 0 26 files changed, 123 insertions(+), 44 deletions(-) rename application/tests/{classes => tests}/.htaccess (100%) rename {application/tests/classes/commands => framework/main/tests}/.htaccess (100%) rename {application/tests/classes/commands/console => framework/main/tests/commands}/.htaccess (100%) rename {application/tests/classes/controller => framework/main/tests/commands/console}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/commands/console/class_TestsConsoleMainCommand.php (100%) rename {application/tests/classes/controller/console => framework/main/tests/controller}/.htaccess (100%) rename {application/tests/classes/filter => framework/main/tests/controller/console}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/controller/console/class_TestsConsoleDefaultNewsController.php (100%) rename {application/tests/classes/filter/tests => framework/main/tests/filter}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/filter/class_BaseTestsFilter.php (100%) rename {application/tests/classes/filter/tests/configuration => framework/main/tests/filter/tests}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/filter/tests/class_Tests (100%) rename {application/tests/classes/filter/tests/configuration/classes => framework/main/tests/filter/tests/configuration}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/filter/tests/configuration/class_TestConfiguration (100%) rename {application/tests/classes/filter/tests/requirements => framework/main/tests/filter/tests/configuration/classes}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php (100%) rename {application/tests/classes/resolver => framework/main/tests/filter/tests/requirements}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/filter/tests/requirements/class_TestsPhpRequirementsFilter.php (100%) rename {application/tests/classes/resolver/command => framework/main/tests/resolver}/.htaccess (100%) rename {application/tests/classes/resolver/command/console => framework/main/tests/resolver/command}/.htaccess (100%) rename {application/tests/classes/resolver/controller => framework/main/tests/resolver/command/console}/.htaccess (100%) rename {application/tests/classes => framework/main/tests}/resolver/command/console/class_TestsConsoleCommandResolver.php (100%) create mode 100644 framework/main/tests/resolver/controller/.htaccess rename {application/tests/classes => framework/main/tests}/resolver/controller/class_TestsConsoleControllerResolver.php (100%) diff --git a/application/tests/init.php b/application/tests/init.php index d11063e9..77c9fb87 100644 --- a/application/tests/init.php +++ b/application/tests/init.php @@ -38,3 +38,12 @@ ApplicationHelper::createDebugInstance('ApplicationHelper'); // This application needs a database connection then we have to simply include // the framework/database.php script require($cfg->getConfigEntry('base_path') . 'framework/database.php'); + +// 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/application/tests/classes/.htaccess b/application/tests/tests/.htaccess similarity index 100% rename from application/tests/classes/.htaccess rename to application/tests/tests/.htaccess diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 808edcf5..f4a69ab6 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -124,6 +124,11 @@ class ClassLoader { 'middleware' // The middleware ); + /** + * Registered paths where test classes can be found. These are all relative + * to base_path . + */ + private static $testPaths = array(); /** * The protected constructor. Please use the factory method below, or use @@ -132,7 +137,7 @@ class ClassLoader { * @return void */ protected function __construct () { - // Is currently empty + // This is empty for now } /** @@ -197,13 +202,16 @@ class ClassLoader { $loaderInstance = self::getSelfInstance(); // Load all classes - foreach (self::$frameworkPaths as $pathName) { + foreach (self::$frameworkPaths as $shortPath) { // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); + //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); // Try to load the framework classes - $loaderInstance->scanClassPath('framework/main/' . $pathName . '/'); + $loaderInstance->scanClassPath(sprintf('framework/main/%s/', $shortPath)); } // END - foreach + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -219,12 +227,20 @@ class ClassLoader { $cfg = FrameworkConfiguration::getSelfInstance(); // Load all classes for the application - foreach (self::$frameworkPaths as $class) { + foreach (self::$frameworkPaths as $shortPath) { + // Debug message + //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); + // Create path name - $pathName = sprintf('%s/%s/%s', $cfg->getConfigEntry('application_path'), $cfg->getConfigEntry('app_name'), $class); + $pathName = realpath(sprintf( + '%s/%s/%s', + $cfg->getConfigEntry('application_path'), + $cfg->getConfigEntry('app_name'), + $shortPath + )); // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: pathName=%s' . PHP_EOL, __METHOD__, __LINE__, $pathName); + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); // Is the path readable? if (is_dir($pathName)) { @@ -232,56 +248,59 @@ class ClassLoader { ClassLoader::getSelfInstance()->scanClassPath($pathName); } // END - if } // END - foreach + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** - * Initializes our loader class + * Scans for test classes, etc. * - * @param $configInstance Configuration class instance * @return void */ - protected function initLoader (FrameworkConfiguration $configInstance) { - // Set configuration instance - $this->configInstance = $configInstance; - - // Construct the FQFN for the cache - if (!defined('DEVELOPER')) { - $this->listCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'list-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; - $this->classCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'class-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; - } // END - if - - // Set suffix and prefix from configuration - $this->suffix = $configInstance->getConfigEntry('class_suffix'); - $this->prefix = $configInstance->getConfigEntry('class_prefix'); + public static function scanTestsClasses () { + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); - // Set own instance - self::$selfInstance = $this; + // Get config instance + $cfg = FrameworkConfiguration::getSelfInstance(); - // Skip here if no dev-mode - if (defined('DEVELOPER')) { - return; - } // END - if + // Load all classes for the application + foreach (self::$testPaths as $shortPath) { + // Debug message + //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); - // IS the cache there? - if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) { - // Get content - $cacheContent = file_get_contents($this->listCacheFQFN); + // Create path name + $pathName = realpath(sprintf( + '%s/%s', + $cfg->getConfigEntry('base_path'), + $shortPath + )); - // And convert it - $this->foundClasses = json_decode($cacheContent); + // Debug message + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); - // List has been restored from cache! - $this->listCached = TRUE; - } // END - if + // Is the path readable? + if (is_dir($pathName)) { + // Try to load the application classes + ClassLoader::getSelfInstance()->scanClassPath($pathName); + } // END - if + } // END - foreach - // Does the class cache exist? - if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) { - // Then include it - require($this->classCacheFQFN); + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); + } - // Mark the class cache as loaded - $this->classesCached = TRUE; - } // END - if + /** + * Registeres given relative path where test classes reside. For regular + * framework uses, they should not be loaded (and used). + * + * @param $relativePath Relative path to test classes + * @return void + */ + public static function registerTestsPath ($relativePath) { + // "Register" it + self::$testPaths[$relativePath] = $relativePath; } /** @@ -417,6 +436,56 @@ class ClassLoader { $this->prefix = $oldPrefix; } + /** + * Initializes our loader class + * + * @param $configInstance Configuration class instance + * @return void + */ + private function initLoader (FrameworkConfiguration $configInstance) { + // Set configuration instance + $this->configInstance = $configInstance; + + // Construct the FQFN for the cache + if (!defined('DEVELOPER')) { + $this->listCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'list-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; + $this->classCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'class-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; + } // END - if + + // Set suffix and prefix from configuration + $this->suffix = $configInstance->getConfigEntry('class_suffix'); + $this->prefix = $configInstance->getConfigEntry('class_prefix'); + + // Set own instance + self::$selfInstance = $this; + + // Skip here if no dev-mode + if (defined('DEVELOPER')) { + return; + } // END - if + + // IS the cache there? + if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) { + // Get content + $cacheContent = file_get_contents($this->listCacheFQFN); + + // And convert it + $this->foundClasses = json_decode($cacheContent); + + // List has been restored from cache! + $this->listCached = TRUE; + } // END - if + + // Does the class cache exist? + if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) { + // Then include it + require($this->classCacheFQFN); + + // Mark the class cache as loaded + $this->classesCached = TRUE; + } // END - if + } + /** * Tries to find the given class in our list. This method ignores silently * missing classes or interfaces. So if you use class_exists() this method diff --git a/application/tests/classes/commands/.htaccess b/framework/main/tests/.htaccess similarity index 100% rename from application/tests/classes/commands/.htaccess rename to framework/main/tests/.htaccess diff --git a/application/tests/classes/commands/console/.htaccess b/framework/main/tests/commands/.htaccess similarity index 100% rename from application/tests/classes/commands/console/.htaccess rename to framework/main/tests/commands/.htaccess diff --git a/application/tests/classes/controller/.htaccess b/framework/main/tests/commands/console/.htaccess similarity index 100% rename from application/tests/classes/controller/.htaccess rename to framework/main/tests/commands/console/.htaccess diff --git a/application/tests/classes/commands/console/class_TestsConsoleMainCommand.php b/framework/main/tests/commands/console/class_TestsConsoleMainCommand.php similarity index 100% rename from application/tests/classes/commands/console/class_TestsConsoleMainCommand.php rename to framework/main/tests/commands/console/class_TestsConsoleMainCommand.php diff --git a/application/tests/classes/controller/console/.htaccess b/framework/main/tests/controller/.htaccess similarity index 100% rename from application/tests/classes/controller/console/.htaccess rename to framework/main/tests/controller/.htaccess diff --git a/application/tests/classes/filter/.htaccess b/framework/main/tests/controller/console/.htaccess similarity index 100% rename from application/tests/classes/filter/.htaccess rename to framework/main/tests/controller/console/.htaccess diff --git a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php b/framework/main/tests/controller/console/class_TestsConsoleDefaultNewsController.php similarity index 100% rename from application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php rename to framework/main/tests/controller/console/class_TestsConsoleDefaultNewsController.php diff --git a/application/tests/classes/filter/tests/.htaccess b/framework/main/tests/filter/.htaccess similarity index 100% rename from application/tests/classes/filter/tests/.htaccess rename to framework/main/tests/filter/.htaccess diff --git a/application/tests/classes/filter/class_BaseTestsFilter.php b/framework/main/tests/filter/class_BaseTestsFilter.php similarity index 100% rename from application/tests/classes/filter/class_BaseTestsFilter.php rename to framework/main/tests/filter/class_BaseTestsFilter.php diff --git a/application/tests/classes/filter/tests/configuration/.htaccess b/framework/main/tests/filter/tests/.htaccess similarity index 100% rename from application/tests/classes/filter/tests/configuration/.htaccess rename to framework/main/tests/filter/tests/.htaccess diff --git a/application/tests/classes/filter/tests/class_Tests b/framework/main/tests/filter/tests/class_Tests similarity index 100% rename from application/tests/classes/filter/tests/class_Tests rename to framework/main/tests/filter/tests/class_Tests diff --git a/application/tests/classes/filter/tests/configuration/classes/.htaccess b/framework/main/tests/filter/tests/configuration/.htaccess similarity index 100% rename from application/tests/classes/filter/tests/configuration/classes/.htaccess rename to framework/main/tests/filter/tests/configuration/.htaccess diff --git a/application/tests/classes/filter/tests/configuration/class_TestConfiguration b/framework/main/tests/filter/tests/configuration/class_TestConfiguration similarity index 100% rename from application/tests/classes/filter/tests/configuration/class_TestConfiguration rename to framework/main/tests/filter/tests/configuration/class_TestConfiguration diff --git a/application/tests/classes/filter/tests/requirements/.htaccess b/framework/main/tests/filter/tests/configuration/classes/.htaccess similarity index 100% rename from application/tests/classes/filter/tests/requirements/.htaccess rename to framework/main/tests/filter/tests/configuration/classes/.htaccess diff --git a/application/tests/classes/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php similarity index 100% rename from application/tests/classes/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php rename to framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php diff --git a/application/tests/classes/resolver/.htaccess b/framework/main/tests/filter/tests/requirements/.htaccess similarity index 100% rename from application/tests/classes/resolver/.htaccess rename to framework/main/tests/filter/tests/requirements/.htaccess diff --git a/application/tests/classes/filter/tests/requirements/class_TestsPhpRequirementsFilter.php b/framework/main/tests/filter/tests/requirements/class_TestsPhpRequirementsFilter.php similarity index 100% rename from application/tests/classes/filter/tests/requirements/class_TestsPhpRequirementsFilter.php rename to framework/main/tests/filter/tests/requirements/class_TestsPhpRequirementsFilter.php diff --git a/application/tests/classes/resolver/command/.htaccess b/framework/main/tests/resolver/.htaccess similarity index 100% rename from application/tests/classes/resolver/command/.htaccess rename to framework/main/tests/resolver/.htaccess diff --git a/application/tests/classes/resolver/command/console/.htaccess b/framework/main/tests/resolver/command/.htaccess similarity index 100% rename from application/tests/classes/resolver/command/console/.htaccess rename to framework/main/tests/resolver/command/.htaccess diff --git a/application/tests/classes/resolver/controller/.htaccess b/framework/main/tests/resolver/command/console/.htaccess similarity index 100% rename from application/tests/classes/resolver/controller/.htaccess rename to framework/main/tests/resolver/command/console/.htaccess diff --git a/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php similarity index 100% rename from application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php rename to framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php diff --git a/framework/main/tests/resolver/controller/.htaccess b/framework/main/tests/resolver/controller/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/resolver/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php b/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php similarity index 100% rename from application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php rename to framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php -- 2.30.2