Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / application / tests / class_ApplicationHelper.php
index e2bb528d2f3f15e4ad9c3ca868a49ab2811c9f97..eab5a2c70052e6465f7c54fa76c292b56657c3ec 100644 (file)
@@ -1,14 +1,16 @@
 <?php
-// Own namespace
-namespace CoreFramework\Helper\Application;
+// Must be this namespace, else the launcher cannot find the class.
+namespace Org\Mxchange\CoreFramework\Helper\Application;
 
 // Import framework stuff
-use CoreFramework\Manager\ManageableApplication;
-use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Registry\Registerable;
-use CoreFramework\Registry\Generic\Registry;
-use CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Loader\ClassLoader;
+use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 
 /**
  * A class holding general data about the application and some methods for
@@ -155,37 +157,54 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
        }
 
        /**
-        * Launches the test suite
+        * 1) Setups application data
         *
         * @return      void
         */
-       public final function entryPoint () {
-               // Set this application in registry
-               Registry::getRegistry()->addInstance('app', $this);
+       public function setupApplicationData () {
+               // Set all application data
+               $this->setAppName('Unit tests and more');
+               $this->setAppVersion('0.0.0');
+               $this->setAppShortName('tests');
+       }
 
-               // Default response is console
-               $response = self::getResponseTypeFromSystem();
-               $responseType = self::getResponseTypeFromSystem();
+       /**
+        * 2) Does initial stuff before starting the application
+        *
+        * @return      void
+        */
+       public function initApplication () {
+               // Get config instance
+               $cfg = FrameworkBootstrap::getConfigurationInstance();
 
-               // Create a new request object
-               $requestInstance = ObjectFactory::createObjectByName(sprintf('CoreFramework\Request\%sRequest', self::convertToClassName($response)));
+               // Initialize output system
+               self::createDebugInstance('ApplicationHelper');
 
-               // Remember request instance here
-               $this->setRequestInstance($requestInstance);
+               /*
+                * This application needs a database connection then simply call init
+                * method.
+                */
+               FrameworkBootstrap::initDatabaseInstance();
 
-               // Do we have another response?
-               if ($requestInstance->isRequestElementSet('request')) {
-                       // Then use it
-                       $response = strtolower($requestInstance->getRequestElement('request'));
-                       $responseType = $response;
-               } // END - if
+               // Register core tests
+               ClassLoader::registerTestsPath('framework/main/tests');
 
-               // ... and a new response object
-               $responseClass = sprintf('CoreFramework\Response\%sResponse', self::convertToClassName($response));
-               $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
+               // Register own tests
+               ClassLoader::registerTestsPath('application/tests/tests');
 
-               // Remember response instance here
-               $this->setResponseInstance($responseInstance);
+               // 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');
@@ -200,7 +219,14 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                } // END - if
 
                // Get a controller resolver
-               $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
+               $resolverClass = sprintf(
+                       'Org\Mxchange\CoreFramework\Tests\Resolver\Controller\%s',
+                       self::convertToClassName(sprintf(
+                               '%s_%s_controller_resolver',
+                               $this->getAppShortName(),
+                               FrameworkBootstrap::getRequestTypeFromSystem()
+                       ))
+               );
                $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
 
                // Get a controller instance as well
@@ -210,9 +236,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
 
                // -------------------------- Shutdown phase --------------------------
-               // Shutting down the hub by saying "good bye" to all connected peers
-               // and other hubs, flushing all queues and caches.
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
+               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.)');
        }
@@ -237,7 +261,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
         * @return      $masterTemplateName             Name of the master template
         */
        public function buildMasterTemplateName () {
-               return 'node_main';
+               return 'tests_main';
        }
 
        /**