* @version 0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team * @license GNU GPL 3.0 or any newer version * * 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 ApplicationHelper extends BaseApplication implements ManageableApplication, Registerable { /** * Private constructor * * @return void */ private function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Getter for an instance of this class * * @return $selfInstance An instance of this class */ public static final function getSelfInstance () { // Is the instance there? if (is_null(self::getApplicationInstance())) { // Then set it self::setApplicationInstance(new ApplicationHelper()); } // Return the instance return self::getApplicationInstance(); } /** * 1) Setups application data * * @return void */ public function setupApplicationData () { // Set all application data $this->setAppName('Unit tests and more'); $this->setAppVersion('0.0.0'); $this->setAppShortName('tests'); } /** * 2) Does initial stuff before starting the application * * @return void */ public function initApplication () { // Get config instance $cfg = FrameworkBootstrap::getConfigurationInstance(); // Initialize output system self::createDebugInstance('ApplicationHelper'); /* * This application needs a database connection then simply call init * method. */ FrameworkBootstrap::initDatabaseInstance(); // Register core tests ClassLoader::registerTestsPath('framework/main/tests'); // Register own tests ClassLoader::registerTestsPath('application/tests/tests'); // Scan for them now ClassLoader::scanTestsClasses(); } /** * 3) Launches the application * * @return void */ public function launchApplication () { // Get request/response instances $requestInstance = FrameworkBootstrap::getRequestInstance(); $responseInstance = FrameworkBootstrap::getResponseInstance(); // Get the parameter from the request $commandName = $requestInstance->getRequestElement('command'); // If it is null then get default command if (is_null($commandName)) { // Get default command $commandName = $responseInstance->determineDefaultCommand(); // Set it in request $requestInstance->setRequestElement('command', $commandName); } // Configuration entry key $configEntry = sprintf( '%s_%s_controller_resolver_class', $this->getAppShortName(), FrameworkBootstrap::getRequestTypeFromSystem() ); // Get a controller resolver instance $resolverInstance = ObjectFactory::createObjectByConfiguredName($configEntry, [ $commandName, ]); // Get a controller instance as well $this->setControllerInstance($resolverInstance->resolveController()); // Launch the test suite here $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); // -------------------------- Shutdown phase -------------------------- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...'); $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); } /** * Handle the indexed array of fatal messages and puts them out in an * acceptable fasion * * @param $messageList An array of fatal messages * @return void */ public function handleFatalMessages (array $messageList) { // Walk through all messages foreach ($messageList as $message) { exit(__METHOD__ . ':MSG:' . $message); } } /** * Builds the master template's name * * @return $masterTemplateName Name of the master template */ public function buildMasterTemplateName () { return 'tests_main'; } /** * Assigns extra application-depending data * * @param $templateInstance An instance of a CompileableTemplate class * @return void * @todo Nothing to add? */ public function assignExtraTemplateData (CompileableTemplate $templateInstance) { $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString()); } }