From: Roland Haeder Date: Sun, 26 Feb 2017 16:07:55 +0000 (+0100) Subject: Moving-session has started: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e2c64b8dbc2e98f397b93152bab1f601df9c758e;p=core.git 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. Signed-off-by: Roland Häder --- diff --git a/application/tests/classes/.htaccess b/application/tests/classes/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/commands/.htaccess b/application/tests/classes/commands/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/commands/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/commands/console/.htaccess b/application/tests/classes/commands/console/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/commands/console/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/commands/console/class_TestsConsoleMainCommand.php b/application/tests/classes/commands/console/class_TestsConsoleMainCommand.php deleted file mode 100644 index ce512ff7..00000000 --- a/application/tests/classes/commands/console/class_TestsConsoleMainCommand.php +++ /dev/null @@ -1,101 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestsConsoleMainCommand extends BaseCommand implements Commandable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $commandInstance An instance a prepared command class - */ - public static final function createTestsConsoleMainCommand (CommandResolver $resolverInstance) { - // Get new instance - $commandInstance = new TestsConsoleMainCommand(); - - // Set the application instance - $commandInstance->setResolverInstance($resolverInstance); - - // Return the prepared instance - return $commandInstance; - } - - /** - * Executes the given command with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Debug message - self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Starting tests ... ---'); - - // Get controller - $controllerInstance = Registry::getRegistry()->getInstance('controller'); - - // Run all tests - $controllerInstance->executeTestsFilters($requestInstance, $responseInstance); - - // Debug message - self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main ... ---'); - } - - /** - * Adds extra filters to the given controller instance - * - * @param $controllerInstance A controller instance - * @param $requestInstance An instance of a class with an Requestable interface - * @return void - */ - public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Add pre filters (e.g. for requirements checks) - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('tests_php_requirements_filter_class')); - - // Add 'tests' filters which will run the actual tests - $controllerInstance->addTestsFilter(ObjectFactory::createObjectByConfiguredName('tests_configuration_classes_loadable_test_filter_class')); - } - -} diff --git a/application/tests/classes/controller/.htaccess b/application/tests/classes/controller/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/controller/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/controller/console/.htaccess b/application/tests/classes/controller/console/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/controller/console/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php b/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php deleted file mode 100644 index d86ebf35..00000000 --- a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php +++ /dev/null @@ -1,145 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestsConsoleDefaultNewsController extends BaseController implements Controller { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Init additional filter chains - foreach (array('bootstrap', 'tests', 'shutdown') as $filterChain) { - $this->initFilterChain($filterChain); - } // END - foreach - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $controllerInstance A prepared instance of this class - */ - public static final function createTestsConsoleDefaultNewsController (CommandResolver $resolverInstance) { - // Create the instance - $controllerInstance = new TestsConsoleDefaultNewsController(); - - // Set the command resolver - $controllerInstance->setResolverInstance($resolverInstance); - - // Add news filters to this controller - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter_class')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter_class')); - - // Return the prepared instance - return $controllerInstance; - } - - /** - * Handles the given request and response - * - * @param $requestInstance An instance of a request class - * @param $responseInstance An instance of a response class - * @return void - */ - public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the post filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); - } - - /** - * Add a bootstrap filter - * - * @param $filterInstance A Filterable class - * @return void - */ - public function addBootstrapFilter (Filterable $filterInstance) { - $this->addFilter('bootstrap', $filterInstance); - } - - /** - * Add a tests filter - * - * @param $filterInstance A Filterable class - * @return void - */ - public function addTestsFilter (Filterable $filterInstance) { - $this->addFilter('tests', $filterInstance); - } - - /** - * Executes all bootstrap filters - * - * @param $requestInstance A Requestable class - * @param $responseInstance A Responseable class - * @return void - */ - public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) { - $this->executeFilters('bootstrap', $requestInstance, $responseInstance); - } - - /** - * Executes all tests filters - * - * @param $requestInstance A Requestable class - * @param $responseInstance A Responseable class - * @return void - */ - public function executeTestsFilters (Requestable $requestInstance, Responseable $responseInstance) { - $this->executeFilters('tests', $requestInstance, $responseInstance); - } - -} diff --git a/application/tests/classes/filter/.htaccess b/application/tests/classes/filter/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/filter/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/filter/class_BaseTestsFilter.php b/application/tests/classes/filter/class_BaseTestsFilter.php deleted file mode 100644 index 04a141f2..00000000 --- a/application/tests/classes/filter/class_BaseTestsFilter.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class BaseTestsFilter extends BaseFilter { - /** - * Protected constructor - * - * @param $className Real name of class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - } - -} diff --git a/application/tests/classes/filter/tests/.htaccess b/application/tests/classes/filter/tests/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/filter/tests/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/filter/tests/class_Tests b/application/tests/classes/filter/tests/class_Tests deleted file mode 100644 index 9f84cded..00000000 --- a/application/tests/classes/filter/tests/class_Tests +++ /dev/null @@ -1,70 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class Tests???Filter extends BaseTestsFilter implements Filterable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this filter class - * - * @return $filterInstance An instance of this filter class - */ - public final static function createTests???Filter () { - // Get a new instance - $filterInstance = new Tests???Filter(); - - // Return the instance - return $filterInstance; - } - - /** - * Executes the filter with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @todo 0% done - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub('Please implement this method.'); - } - -} diff --git a/application/tests/classes/filter/tests/configuration/.htaccess b/application/tests/classes/filter/tests/configuration/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/filter/tests/configuration/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/filter/tests/configuration/class_TestConfiguration b/application/tests/classes/filter/tests/configuration/class_TestConfiguration deleted file mode 100644 index 76afc51a..00000000 --- a/application/tests/classes/filter/tests/configuration/class_TestConfiguration +++ /dev/null @@ -1,70 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestConfiguration???Filter extends BaseTestsFilter implements Filterable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this filter class - * - * @return $filterInstance An instance of this filter class - */ - public final static function createTestConfiguration???Filter () { - // Get a new instance - $filterInstance = new TestConfiguration???Filter(); - - // Return the instance - return $filterInstance; - } - - /** - * Executes the filter with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @todo 0% done - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub('Please implement this method.'); - } - -} diff --git a/application/tests/classes/filter/tests/configuration/classes/.htaccess b/application/tests/classes/filter/tests/configuration/classes/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/filter/tests/configuration/classes/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/application/tests/classes/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php deleted file mode 100644 index 175f5173..00000000 --- a/application/tests/classes/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements Filterable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this filter class - * - * @return $filterInstance An instance of this filter class - */ - public final static function createTestConfigurationLoadableClassesFilter () { - // Get a new instance - $filterInstance = new TestConfigurationLoadableClassesFilter(); - - // Return the instance - return $filterInstance; - } - - /** - * Executes the filter with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @todo 0% done - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub('Please implement this method.'); - } - -} diff --git a/application/tests/classes/filter/tests/requirements/.htaccess b/application/tests/classes/filter/tests/requirements/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/filter/tests/requirements/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/filter/tests/requirements/class_TestsPhpRequirementsFilter.php b/application/tests/classes/filter/tests/requirements/class_TestsPhpRequirementsFilter.php deleted file mode 100644 index 969d9cf7..00000000 --- a/application/tests/classes/filter/tests/requirements/class_TestsPhpRequirementsFilter.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestsPhpRequirementsFilter extends BaseTestsFilter implements Filterable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this filter class - * - * @return $filterInstance An instance of this filter class - */ - public final static function createTestsPhpRequirementsFilter () { - // Get a new instance - $filterInstance = new TestsPhpRequirementsFilter(); - - // Return the instance - return $filterInstance; - } - - /** - * Executes the filter with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @todo 0% done - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub('Please implement this method.'); - } - -} diff --git a/application/tests/classes/resolver/.htaccess b/application/tests/classes/resolver/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/resolver/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/resolver/command/.htaccess b/application/tests/classes/resolver/command/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/resolver/command/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/resolver/command/console/.htaccess b/application/tests/classes/resolver/command/console/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/resolver/command/console/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php b/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php deleted file mode 100644 index d7dfd9f6..00000000 --- a/application/tests/classes/resolver/command/console/class_TestsConsoleCommandResolver.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestsConsoleCommandResolver extends BaseCommandResolver implements CommandResolver { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set prefix to "TestsConsole" - $this->setClassPrefix('tests_console'); - } - - /** - * Creates an instance of a TestsConsole command resolver with a given default command - * - * @param $commandName The default command we shall execute - * @param $applicationInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance - * @throws EmptyVariableException Thrown if default command is not set - * @throws InvalidCommandException Thrown if default command is invalid - */ - public static final function createTestsConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { - // Create the new instance - $resolverInstance = new TestsConsoleCommandResolver(); - - // Is the variable $commandName set and the command is valid? - if (empty($commandName)) { - // Then thrown an exception here - throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif ($resolverInstance->isCommandValid('CoreFramework\Tests\Command', $commandName) === FALSE) { - // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($applicationInstance); - $resolverInstance->setNamespace('CoreFramework\Tests\Command'); - - // Return the prepared instance - return $resolverInstance; - } - -} diff --git a/application/tests/classes/resolver/controller/.htaccess b/application/tests/classes/resolver/controller/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/application/tests/classes/resolver/controller/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php b/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php deleted file mode 100644 index 18124fa4..00000000 --- a/application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php +++ /dev/null @@ -1,114 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class TestsConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set prefix to "TestsConsole" - $this->setClassPrefix('tests_console'); - } - - /** - * Creates an instance of a resolver class with a given command - * - * @param $controllerName The controller we shall resolve - * @param $applicationInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared controller resolver instance - * @throws EmptyVariableException Thrown if default command is not set - * @throws InvalidControllerException Thrown if default controller is invalid - */ - public static final function createTestsConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) { - // Create the new instance - $resolverInstance = new TestsConsoleControllerResolver(); - - // Is the variable $controllerName set and the command is valid? - if (empty($controllerName)) { - // Then thrown an exception here - throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif ($resolverInstance->isControllerValid('CoreFramework\Tests\Controller', $controllerName) === FALSE) { - // Invalid command found - throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($applicationInstance); - - // Set namespace and controller name - $resolverInstance->setNamespace('CoreFramework\Tests\Controller'); - $resolverInstance->setControllerName($controllerName); - - // Return the prepared instance - return $resolverInstance; - } - - /** - * Resolves the default controller of the given command - * - * @return $controllerInstance A controller instance for the default - * command - * @throws InvalidControllerInstanceException Thrown if $controllerInstance - * is invalid - */ - public function resolveController () { - // Init variables - $controllerName = ''; - $controllerInstance = NULL; - - // Get namespace and command name - $controllerName = $this->getControllerName(); - - // Get the command - $controllerInstance = $this->loadController($controllerName); - - // And validate it - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // This command has an invalid instance! - throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); - } // END - if - - // Set last controller - $this->setResolvedInstance($controllerInstance); - - // Return the maybe resolved instance - return $controllerInstance; - } - -} 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/tests/.htaccess b/application/tests/tests/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/application/tests/tests/.htaccess @@ -0,0 +1 @@ +Deny from all 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/framework/main/tests/.htaccess b/framework/main/tests/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/commands/.htaccess b/framework/main/tests/commands/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/commands/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/commands/console/.htaccess b/framework/main/tests/commands/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/commands/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/commands/console/class_TestsConsoleMainCommand.php b/framework/main/tests/commands/console/class_TestsConsoleMainCommand.php new file mode 100644 index 00000000..ce512ff7 --- /dev/null +++ b/framework/main/tests/commands/console/class_TestsConsoleMainCommand.php @@ -0,0 +1,101 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestsConsoleMainCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public static final function createTestsConsoleMainCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new TestsConsoleMainCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Starting tests ... ---'); + + // Get controller + $controllerInstance = Registry::getRegistry()->getInstance('controller'); + + // Run all tests + $controllerInstance->executeTestsFilters($requestInstance, $responseInstance); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main ... ---'); + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add pre filters (e.g. for requirements checks) + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('tests_php_requirements_filter_class')); + + // Add 'tests' filters which will run the actual tests + $controllerInstance->addTestsFilter(ObjectFactory::createObjectByConfiguredName('tests_configuration_classes_loadable_test_filter_class')); + } + +} diff --git a/framework/main/tests/controller/.htaccess b/framework/main/tests/controller/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/controller/console/.htaccess b/framework/main/tests/controller/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/controller/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/controller/console/class_TestsConsoleDefaultNewsController.php b/framework/main/tests/controller/console/class_TestsConsoleDefaultNewsController.php new file mode 100644 index 00000000..d86ebf35 --- /dev/null +++ b/framework/main/tests/controller/console/class_TestsConsoleDefaultNewsController.php @@ -0,0 +1,145 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestsConsoleDefaultNewsController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Init additional filter chains + foreach (array('bootstrap', 'tests', 'shutdown') as $filterChain) { + $this->initFilterChain($filterChain); + } // END - foreach + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + */ + public static final function createTestsConsoleDefaultNewsController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new TestsConsoleDefaultNewsController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // Add news filters to this controller + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter_class')); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the post filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } + + /** + * Add a bootstrap filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addBootstrapFilter (Filterable $filterInstance) { + $this->addFilter('bootstrap', $filterInstance); + } + + /** + * Add a tests filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addTestsFilter (Filterable $filterInstance) { + $this->addFilter('tests', $filterInstance); + } + + /** + * Executes all bootstrap filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->executeFilters('bootstrap', $requestInstance, $responseInstance); + } + + /** + * Executes all tests filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeTestsFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->executeFilters('tests', $requestInstance, $responseInstance); + } + +} diff --git a/framework/main/tests/filter/.htaccess b/framework/main/tests/filter/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/filter/class_BaseTestsFilter.php b/framework/main/tests/filter/class_BaseTestsFilter.php new file mode 100644 index 00000000..04a141f2 --- /dev/null +++ b/framework/main/tests/filter/class_BaseTestsFilter.php @@ -0,0 +1,42 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseTestsFilter extends BaseFilter { + /** + * Protected constructor + * + * @param $className Real name of class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + +} diff --git a/framework/main/tests/filter/tests/.htaccess b/framework/main/tests/filter/tests/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/filter/tests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/filter/tests/class_Tests b/framework/main/tests/filter/tests/class_Tests new file mode 100644 index 00000000..9f84cded --- /dev/null +++ b/framework/main/tests/filter/tests/class_Tests @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class Tests???Filter extends BaseTestsFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createTests???Filter () { + // Get a new instance + $filterInstance = new Tests???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } + +} diff --git a/framework/main/tests/filter/tests/configuration/.htaccess b/framework/main/tests/filter/tests/configuration/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/filter/tests/configuration/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/filter/tests/configuration/class_TestConfiguration b/framework/main/tests/filter/tests/configuration/class_TestConfiguration new file mode 100644 index 00000000..76afc51a --- /dev/null +++ b/framework/main/tests/filter/tests/configuration/class_TestConfiguration @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestConfiguration???Filter extends BaseTestsFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createTestConfiguration???Filter () { + // Get a new instance + $filterInstance = new TestConfiguration???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } + +} diff --git a/framework/main/tests/filter/tests/configuration/classes/.htaccess b/framework/main/tests/filter/tests/configuration/classes/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/filter/tests/configuration/classes/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php new file mode 100644 index 00000000..175f5173 --- /dev/null +++ b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createTestConfigurationLoadableClassesFilter () { + // Get a new instance + $filterInstance = new TestConfigurationLoadableClassesFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } + +} diff --git a/framework/main/tests/filter/tests/requirements/.htaccess b/framework/main/tests/filter/tests/requirements/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/filter/tests/requirements/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/filter/tests/requirements/class_TestsPhpRequirementsFilter.php b/framework/main/tests/filter/tests/requirements/class_TestsPhpRequirementsFilter.php new file mode 100644 index 00000000..969d9cf7 --- /dev/null +++ b/framework/main/tests/filter/tests/requirements/class_TestsPhpRequirementsFilter.php @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestsPhpRequirementsFilter extends BaseTestsFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createTestsPhpRequirementsFilter () { + // Get a new instance + $filterInstance = new TestsPhpRequirementsFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } + +} diff --git a/framework/main/tests/resolver/.htaccess b/framework/main/tests/resolver/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/resolver/command/.htaccess b/framework/main/tests/resolver/command/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/resolver/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/resolver/command/console/.htaccess b/framework/main/tests/resolver/command/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/framework/main/tests/resolver/command/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php new file mode 100644 index 00000000..d7dfd9f6 --- /dev/null +++ b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php @@ -0,0 +1,78 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestsConsoleCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "TestsConsole" + $this->setClassPrefix('tests_console'); + } + + /** + * Creates an instance of a TestsConsole command resolver with a given default command + * + * @param $commandName The default command we shall execute + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidCommandException Thrown if default command is invalid + */ + public static final function createTestsConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new TestsConsoleCommandResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isCommandValid('CoreFramework\Tests\Command', $commandName) === FALSE) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + $resolverInstance->setNamespace('CoreFramework\Tests\Command'); + + // Return the prepared instance + return $resolverInstance; + } + +} 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/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php b/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php new file mode 100644 index 00000000..18124fa4 --- /dev/null +++ b/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php @@ -0,0 +1,114 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TestsConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "TestsConsole" + $this->setClassPrefix('tests_console'); + } + + /** + * Creates an instance of a resolver class with a given command + * + * @param $controllerName The controller we shall resolve + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared controller resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidControllerException Thrown if default controller is invalid + */ + public static final function createTestsConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new TestsConsoleControllerResolver(); + + // Is the variable $controllerName set and the command is valid? + if (empty($controllerName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isControllerValid('CoreFramework\Tests\Controller', $controllerName) === FALSE) { + // Invalid command found + throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Set namespace and controller name + $resolverInstance->setNamespace('CoreFramework\Tests\Controller'); + $resolverInstance->setControllerName($controllerName); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default + * command + * @throws InvalidControllerInstanceException Thrown if $controllerInstance + * is invalid + */ + public function resolveController () { + // Init variables + $controllerName = ''; + $controllerInstance = NULL; + + // Get namespace and command name + $controllerName = $this->getControllerName(); + + // Get the command + $controllerInstance = $this->loadController($controllerName); + + // And validate it + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // This command has an invalid instance! + throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } // END - if + + // Set last controller + $this->setResolvedInstance($controllerInstance); + + // Return the maybe resolved instance + return $controllerInstance; + } + +}