]> git.mxchange.org Git - core.git/commitdiff
Continued with unit tests:
authorRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 21:46:53 +0000 (23:46 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 21:46:53 +0000 (23:46 +0200)
- some refacturing: all detectFoo() methods are now moved from configuration
  to bootstrap class as this seems proper place
- also they can only be called static
- DNS resolver is now globally quieted in tests/bootstrap.php
- created new unit test for FrameworkBootstrap class (partly)
- this origins from configuration unit test

Signed-off-by: Roland Häder <roland@mxchange.org>
12 files changed:
framework/bootstrap/class_FrameworkBootstrap.php
framework/config-global.php
framework/config/class_FrameworkConfiguration.php
framework/main/classes/rng/class_RandomNumberGenerator.php
framework/main/classes/tools/console/class_ConsoleTools.php
framework/main/exceptions/main/class_NullPointerException.php
tests/bootstrap.php
tests/framework/.htaccess [new file with mode: 0644]
tests/framework/bootstrap/.htaccess [new file with mode: 0644]
tests/framework/bootstrap/class_FrameworkBootstrapTest.php [new file with mode: 0644]
tests/framework/config/.htaccess [new file with mode: 0644]
tests/framework/config/FrameworkConfigurationTest.php

index 16e5863d0e3e4d6589f044e70088dc04e880137e..2af601e0d5971c06195dc2cc9107dbc296153cf5 100644 (file)
@@ -6,8 +6,10 @@ namespace CoreFramework\Bootstrap;
 use CoreFramework\Configuration\FrameworkConfiguration;
 use CoreFramework\Connection\Database\DatabaseConnection;
 use CoreFramework\Connector\Database\DatabaseConnector;
+use CoreFramework\Console\Tools\ConsoleTools;
 use CoreFramework\EntryPoint\ApplicationEntryPoint;
 use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\NullPointerException;
 use CoreFramework\Helper\Application\ApplicationHelper;
 use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Manager\ManageableApplication;
@@ -19,6 +21,7 @@ use CoreFramework\Response\Responseable;
 
 // Import SPL stuff
 use \BadMethodCallException;
+use \InvalidArgumentException;
 
 /**
  * A framework-bootstrap class which helps the frameworks to bootstrap ... ;-)
@@ -44,6 +47,11 @@ use \BadMethodCallException;
  */
 final class FrameworkBootstrap {
 
+       /**
+        * Detected server address
+        */
+       private static $serverAddress = NULL;
+
        /**
         * Instance of a Requestable class
         */
@@ -381,6 +389,169 @@ final class FrameworkBootstrap {
                $applicationInstance->setDatabaseInstance($connectionInstance);
        }
 
+       /**
+        * Detects the server address (SERVER_ADDR) and set it in configuration
+        *
+        * @return      $serverAddress  The detected server address
+        * @throws      UnknownHostnameException        If SERVER_NAME cannot be resolved to an IP address
+        * @todo        Have to check some more entries from $_SERVER here
+        */
+       public static function detectServerAddress () {
+               // Is the entry set?
+               if (!isset(self::$serverAddress)) {
+                       // Is it set in $_SERVER?
+                       if (!empty($_SERVER['SERVER_ADDR'])) {
+                               // Set it from $_SERVER
+                               self::$serverAddress = $_SERVER['SERVER_ADDR'];
+                       } elseif (isset($_SERVER['SERVER_NAME'])) {
+                               // Resolve IP address
+                               $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']);
+
+                               // Is it valid?
+                               if ($serverIp === false) {
+                                       /*
+                                        * Why is gethostbyname() returning the host name and not
+                                        * false as many other PHP functions are doing? ;-(
+                                        */
+                                       throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME']));
+                               } // END - if
+
+                               // Al fine, set it
+                               self::$serverAddress = $serverIp;
+                       } else {
+                               // Run auto-detecting through console tools lib
+                               self::$serverAddress = ConsoleTools::acquireSelfIpAddress();
+                       }
+               } // END - if
+
+               // Return it
+               return self::$serverAddress;
+       }
+
+       /**
+        * Setter for default time zone (must be correct!)
+        *
+        * @param       $timezone       The timezone string (e.g. Europe/Berlin)
+        * @return      $success        If timezone was accepted
+        * @throws      NullPointerException    If $timezone is NULL
+        * @throws      InvalidArgumentException        If $timezone is empty
+        */
+       public static function setDefaultTimezone ($timezone) {
+               // Is it null?
+               if (is_null($timezone)) {
+                       // Throw NPE
+                       throw new NullPointerException(NULL, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
+               } elseif (!is_string($timezone)) {
+                       // Is not a string
+                       throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone)));
+               } elseif ((is_string($timezone)) && (empty($timezone))) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('timezone is empty');
+               }
+
+               // Default success
+               $success = FALSE;
+
+               /*
+                * Set desired time zone to prevent date() and related functions to
+                * issue an E_WARNING.
+                */
+               $success = date_default_timezone_set($timezone);
+
+               // Return status
+               return $success;
+       }
+
+       /**
+        * Detects the HTTPS flag
+        *
+        * @return      $https  The detected HTTPS flag or null if failed
+        */
+       public static function detectHttpSecured () {
+               // Default is null
+               $https = NULL;
+
+               // Is HTTPS set?
+               if (self::isHttpSecured()) {
+                       // Then use it
+                       $https = $_SERVER['HTTPS'];
+               } // END - if
+
+               // Return it
+               return $https;
+       }
+
+       /**
+        * Checks whether HTTPS is set in $_SERVER
+        *
+        * @return      $isset  Whether HTTPS is set
+        * @todo        Test more fields
+        */
+       public static function isHttpSecured () {
+               return (isset($_SERVER['HTTPS']));
+       }
+
+       /**
+        * Dectect and return the base URL for all URLs and forms
+        *
+        * @return      $baseUrl        Detected base URL
+        */
+       public static function detectBaseUrl () {
+               // Initialize the URL
+               $protocol = 'http';
+
+               // Do we have HTTPS?
+               if (self::isHttpSecured()) {
+                       // Add the >s< for HTTPS
+                       $protocol = 's';
+               } // END - if
+
+               // Construct the full URL and secure it against CSRF attacks
+               $baseUrl = $protocol . '://' . self::detectDomain() . self::detectScriptPath();
+
+               // Return the URL
+               return $baseUrl;
+       }
+
+       /**
+        * Detect safely and return the full domain where this script is installed
+        *
+        * @return      $fullDomain             The detected full domain
+        */
+       public static function detectDomain () {
+               // Full domain is localnet.invalid by default
+               $fullDomain = 'localnet.invalid';
+
+               // Is the server name there?
+               if (isset($_SERVER['SERVER_NAME'])) {
+                       // Detect the full domain
+                       $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
+               } // END - if
+
+               // Return it
+               return $fullDomain;
+       }
+
+       /**
+        * Detect safely the script path without trailing slash which is the glue
+        * between "http://your-domain.invalid/" and "script-name.php"
+        *
+        * @return      $scriptPath             The script path extracted from $_SERVER['SCRIPT_NAME']
+        */
+       public static function detectScriptPath () {
+               // Default is empty
+               $scriptPath = '';
+
+               // Is the scriptname set?
+               if (isset($_SERVER['SCRIPT_NAME'])) {
+                       // Get dirname from it and replace back-slashes with slashes for lame OSes...
+                       $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME']));
+               } // END - if
+
+               // Return it
+               return $scriptPath;
+       }
+
        /**
         * 1) Loads class scanner and scans all framework's classes and interfaces.
         * This method also registers the class loader's method autoLoad() for the
index 31a7fdc0957aad1b3525528c68a972d2483942af..bf734267fea51f73d3ec970745bff6c3d55747dd 100644 (file)
@@ -39,7 +39,7 @@ $cfg->setConfigEntry('root_base_path', ApplicationEntryPoint::getRootPath() . DI
 $cfg->setConfigEntry('framework_base_path', ApplicationEntryPoint::detectFrameworkPath());
 
 // CFG: BASE-URL
-$cfg->setConfigEntry('base_url', $cfg->detectBaseUrl());
+$cfg->setConfigEntry('base_url', FrameworkBootstrap::detectBaseUrl());
 
 // CFG: DATABASE-TYPE
 $cfg->setConfigEntry('database_type', 'local_file_database');
@@ -47,8 +47,8 @@ $cfg->setConfigEntry('database_type', 'local_file_database');
 // CFG: LOCAL-DATABASE-PATH
 $cfg->setConfigEntry('local_database_path', $cfg->getConfigEntry('root_base_path') . 'db/');
 
-// CFG: TIME-ZONE
-$cfg->setDefaultTimezone('Europe/Berlin');
+// Default timezone
+FrameworkBootstrap::setDefaultTimezone('Europe/Berlin');
 
 // CFG: CLASS-PREFIX
 $cfg->setConfigEntry('class_prefix', 'class_');
@@ -294,13 +294,13 @@ $cfg->setConfigEntry('guest_class', 'CoreFramework\User\Guest\Guest');
 $cfg->setConfigEntry('cookie_expire', (60*60*2)); // Two hours!
 
 // CFG: COOKIE-PATH
-$cfg->setConfigEntry('cookie_path', $cfg->detectScriptPath() . DIRECTORY_SEPARATOR);
+$cfg->setConfigEntry('cookie_path', FrameworkBootstrap::detectScriptPath() . DIRECTORY_SEPARATOR);
 
 // CFG: COOKIE-DOMAIN
-$cfg->setConfigEntry('cookie_domain', $cfg->detectDomain()); // Is mostly the same...
+$cfg->setConfigEntry('cookie_domain', FrameworkBootstrap::detectDomain()); // Is mostly the same...
 
 // CFG: COOKIE-SSL
-$cfg->setConfigEntry('cookie_ssl', $cfg->isHttpSecured());
+$cfg->setConfigEntry('cookie_ssl', FrameworkBootstrap::isHttpSecured());
 
 // CFG: CRYPT-FIXED-SALT
 $cfg->setConfigEntry('crypt_fixed_salt', 'N');
index 26c47d4268062f14b4cb6eda492d96fef71e13db..2521e3c9f4e755dfe6bad2b3619691dcf650ac86 100644 (file)
@@ -127,40 +127,6 @@ class FrameworkConfiguration implements Registerable {
                return $str;
        }
 
-       /**
-        * Setter for default time zone (must be correct!)
-        *
-        * @param       $timezone       The timezone string (e.g. Europe/Berlin)
-        * @return      $success        If timezone was accepted
-        * @throws      NullPointerException    If $timezone is NULL
-        * @throws      InvalidArgumentException        If $timezone is empty
-        */
-       public final function setDefaultTimezone ($timezone) {
-               // Is it null?
-               if (is_null($timezone)) {
-                       // Throw NPE
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($timezone)) {
-                       // Is not a string
-                       throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($timezone)) && (empty($timezone))) {
-                       // Entry is empty
-                       throw new InvalidArgumentException('timezone is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               }
-
-               // Default success
-               $success = FALSE;
-
-               /*
-                * Set desired time zone to prevent date() and related functions to
-                * issue an E_WARNING.
-                */
-               $success = date_default_timezone_set($timezone);
-
-               // Return status
-               return $success;
-       }
-
        /**
         * Checks whether the given configuration key is set
         *
@@ -212,7 +178,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Convert dashes to underscore
-               $configKey = self::convertDashesToUnderscores($configKey);
+               $configKey = $this->convertDashesToUnderscores($configKey);
 
                // Is a valid configuration key provided?
                if (!$this->isConfigurationEntrySet($configKey)) {
@@ -251,7 +217,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Cast to string
-               $configKey = self::convertDashesToUnderscores($configKey);
+               $configKey = $this->convertDashesToUnderscores($configKey);
 
                // Set the configuration value
                //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
@@ -295,7 +261,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Convert dashes to underscore
-               $configKey = self::convertDashesToUnderscores($configKey);
+               $configKey = $this->convertDashesToUnderscores($configKey);
 
                // Is the configuration key there?
                if (!$this->isConfigurationEntrySet($configKey)) {
@@ -307,170 +273,6 @@ class FrameworkConfiguration implements Registerable {
                unset($this->config[$configKey]);
        }
 
-       /**
-        * Detects the server address (SERVER_ADDR) and set it in configuration
-        *
-        * @return      $serverAddress  The detected server address
-        * @throws      UnknownHostnameException        If SERVER_NAME cannot be resolved to an IP address
-        * @todo        Have to check some more entries from $_SERVER here
-        */
-       public function detectServerAddress () {
-               // Is the entry set?
-               if (!$this->isConfigurationEntrySet('server_addr')) {
-                       // Is it set in $_SERVER?
-                       if (isset($_SERVER['SERVER_ADDR'])) {
-                               // Set it from $_SERVER
-                               $this->setServerAddress($_SERVER['SERVER_ADDR']);
-                       } elseif (isset($_SERVER['SERVER_NAME'])) {
-                               // Resolve IP address
-                               $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']);
-
-                               // Is it valid?
-                               if ($serverIp === false) {
-                                       /*
-                                        * Why is gethostbyname() returning the host name and not
-                                        * false as many other PHP functions are doing? ;-(
-                                        */
-                                       throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME']));
-                               } // END - if
-
-                               // Al fine, set it
-                               $this->setServerAddress($serverIp);
-                       } else {
-                               // Run auto-detecting through console tools lib
-                               ConsoleTools::acquireSelfIpAddress();
-                       }
-               } // END - if
-
-               // Now get it from configuration
-               $serverAddress = $this->getServerAddress();
-
-               // Return it
-               return $serverAddress;
-       }
-
-       /**
-        * Setter for SERVER_ADDR
-        *
-        * @param       $serverAddress  New SERVER_ADDR value to set
-        * @return      void
-        */
-       public function setServerAddress ($serverAddress) {
-               // Is a valid configuration key key provided?
-               if (is_null($serverAddress)) {
-                       // Configuration key is null
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($serverAddress)) {
-                       // Is not a string
-                       throw new InvalidArgumentException(sprintf('serverAddress[]=%s is not a string', gettype($serverAddress)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($serverAddress)) && (empty($serverAddress))) {
-                       // Entry is empty
-                       throw new InvalidArgumentException('serverAddress is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               }
-
-               // Set it, please don't do it yourself here
-               $this->setConfigEntry('server_addr', (string) $serverAddress);
-       }
-
-       /**
-        * Getter for SERVER_ADDR
-        *
-        * @return      $serverAddress  New SERVER_ADDR value to set
-        */
-       public function getServerAddress () {
-               return $this->getConfigEntry('server_addr');
-       }
-
-       /**
-        * Detects the HTTPS flag
-        *
-        * @return      $https  The detected HTTPS flag or null if failed
-        */
-       public function detectHttpSecured () {
-               // Default is null
-               $https = NULL;
-
-               // Is HTTPS set?
-               if ($this->isHttpSecured()) {
-                       // Then use it
-                       $https = $_SERVER['HTTPS'];
-               } // END - if
-
-               // Return it
-               return $https;
-       }
-
-       /**
-        * Checks whether HTTPS is set in $_SERVER
-        *
-        * @return      $isset  Whether HTTPS is set
-        * @todo        Test more fields
-        */
-       public function isHttpSecured () {
-               return (isset($_SERVER['HTTPS']));
-       }
-
-       /**
-        * Dectect and return the base URL for all URLs and forms
-        *
-        * @return      $baseUrl        Detected base URL
-        */
-       public function detectBaseUrl () {
-               // Initialize the URL
-               $protocol = 'http';
-
-               // Do we have HTTPS?
-               if ($this->isHttpSecured()) {
-                       // Add the >s< for HTTPS
-                       $protocol = 's';
-               } // END - if
-
-               // Construct the full URL and secure it against CSRF attacks
-               $baseUrl = $protocol . '://' . $this->detectDomain() . $this->detectScriptPath();
-
-               // Return the URL
-               return $baseUrl;
-       }
-
-       /**
-        * Detect safely and return the full domain where this script is installed
-        *
-        * @return      $fullDomain             The detected full domain
-        */
-       public function detectDomain () {
-               // Full domain is localnet.invalid by default
-               $fullDomain = 'localnet.invalid';
-
-               // Is the server name there?
-               if (isset($_SERVER['SERVER_NAME'])) {
-                       // Detect the full domain
-                       $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
-               } // END - if
-
-               // Return it
-               return $fullDomain;
-       }
-
-       /**
-        * Detect safely the script path without trailing slash which is the glue
-        * between "http://your-domain.invalid/" and "script-name.php"
-        *
-        * @return      $scriptPath             The script path extracted from $_SERVER['SCRIPT_NAME']
-        */
-       public function detectScriptPath () {
-               // Default is empty
-               $scriptPath = '';
-
-               // Is the scriptname set?
-               if (isset($_SERVER['SCRIPT_NAME'])) {
-                       // Get dirname from it and replace back-slashes with slashes for lame OSes...
-                       $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME']));
-               } // END - if
-
-               // Return it
-               return $scriptPath;
-       }
-
        /**
         * Getter for field name
         *
index d2229285e9e2f9c4d61c32c2bf0142bd8a844432..31bc3c0a45652dcb4c913969c34540fc66f4f6a2 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Crypto\RandomNumber;
 
 // Import framework stuff
+use CoreFramework\Bootstrap\FrameworkBootstrap;
 use CoreFramework\Object\BaseFrameworkSystem;
 use CoreFramework\Generic\FrameworkInterface;
 
@@ -120,7 +121,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                // Do we have a single server?
                if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') {
                        // Then use that IP for extra security
-                       $serverIp = $this->getConfigInstance()->detectServerAddress();
+                       $serverIp = FrameworkBootstrap::detectServerAddress();
                } // END - if
 
                // Yet-another fixed salt. This is not dependend on server software or date
index 8b5a2a456295a3b6d7e0bd53297afca3bf1f6161..902164101a779b964a6c605c5c9bd158981da47b 100644 (file)
@@ -281,9 +281,6 @@ class ConsoleTools extends BaseFrameworkSystem {
                        ));
                }
 
-               // Set it in configuration
-               FrameworkConfiguration::getSelfInstance()->setServerAddress($ipAddress);
-
                // Return it
                return $ipAddress;
        }
index f8fb0eeeb728d4ebfc4872b8989706a5a0a1ec83..ecb7bac4647c308deaac8568ea1b235b64bd7826 100644 (file)
@@ -36,12 +36,20 @@ class NullPointerException extends FrameworkException {
         * @param       $code   Code number for the exception
         * @return      void
         */
-       public function __construct (FrameworkInterface $class, $code) {
-               // Add a message around the missing class
-               $message = sprintf('[%s:%d] An object instance is set to <em>null</em>.',
-                       $class->__toString(),
-                       $this->getLine()
-               );
+       public function __construct (FrameworkInterface $class = NULL, $code) {
+               // Is the instance set?
+               if (is_null($class)) {
+                       // Add a message around the missing class
+                       $message = sprintf('[unknown:%d] An object instance is set to <em>null</em>.',
+                               $this->getLine()
+                       );
+               } else {
+                       // Add a message around the missing class
+                       $message = sprintf('[%s:%d] An object instance is set to <em>null</em>.',
+                               $class->__toString(),
+                               $this->getLine()
+                       );
+               }
 
                // Call parent constructor
                parent::__construct($message, $code);
index 3d2f1aeeaa92db8df9b1f9cfb24fc48774ef7125..de3ab8eeba73c84fa931fe443b9f9dfdb051ace6 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+// Import needed stuff
+use CoreFramework\Configuration\FrameworkConfiguration;
+
 /*
  * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
  *
@@ -40,3 +43,6 @@ if (extension_loaded('xdebug')) {
 
 // Autoload more stuff
 require dirname(__DIR__) . '/vendor/autoload.php';
+
+// Quiet DNS resolver as this is not wanted here
+FrameworkConfiguration::getSelfInstance()->setConfigEntry('quiet_dns_resolver', TRUE);
diff --git a/tests/framework/.htaccess b/tests/framework/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/tests/framework/bootstrap/.htaccess b/tests/framework/bootstrap/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php
new file mode 100644 (file)
index 0000000..95a847c
--- /dev/null
@@ -0,0 +1,215 @@
+<?php
+
+// Same namespace as target class
+namespace CoreFramework\Bootstrap;
+
+// Inport framework stuff
+use CoreFramework\Console\Tools\ConsoleTools;
+use CoreFramework\Loader\ClassLoader;
+use CoreFramework\Generic\NullPointerException;
+use CoreFramework\Generic\UnsupportedOperationException;
+
+// Import PHPUnit stuff
+use PHPUnit\Framework\Error\Notice;
+use PHPUnit\Framework\TestCase;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+
+/*
+ * Copyright (C) 2017 Roland Haeder<roland@mxchange.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 <http://www.gnu.org/licenses/>.
+ */
+class FrameworkBootstrapTest extends TestCase {
+
+       /**
+        * Own IP address
+        */
+       private static $ipAddress = FALSE;
+
+       /**
+        * Setup test case
+        */
+       public function setUp() {
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
+
+               // Call parent method
+               parent::setUp();
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
+
+       }
+
+       /**
+        * Setup test case
+        */
+       public static function setUpBeforeClass() {
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
+
+               // Call parent method
+               parent::setUpBeforeClass();
+
+               /*
+                * Disable strict naming-convention check in own class loader, because
+                * PHP_Invoker doesn't have namespaces.
+                */
+               ClassLoader::enableStrictNamingConventionCheck(FALSE);
+
+               // Lookup own IP address
+               self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
+       }
+
+       /**
+        * Tests setting a NULL default timezone
+        */
+       public function testSettingNullDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(NullPointerException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(NULL);
+       }
+
+       /**
+        * Tests setting a boolean default timezone
+        */
+       public function testSettingBooleanDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(FALSE);
+       }
+
+       /**
+        * Tests setting a decimal default timezone
+        */
+       public function testSettingDecimalDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(12345);
+       }
+
+       /**
+        * Tests setting a float default timezone
+        */
+       public function testSettingFloatDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(123.45);
+       }
+
+       /**
+        * Tests setting an array default timezone
+        */
+       public function testSettingArrayDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(array());
+       }
+
+       /**
+        * Tests setting an object default timezone
+        */
+       public function testSettingObjectDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone($this);
+       }
+
+       /**
+        * Tests setting a resource default timezone
+        */
+       public function testSettingResourceDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Init some resource
+               $resource = fopen(__FILE__, 'r');
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone($resource);
+       }
+
+       /**
+        * Tests setting an empty default timezone
+        */
+       public function testSettingEmptyDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone('');
+       }
+
+       /**
+        * Tests setting invalid timezone
+        */
+       public function testSettingInvalidDefaultTimezone () {
+               // Expect Notice
+               $this->expectException(Notice::class);
+
+               // Try to set it
+               FrameworkBootstrap::setDefaultTimezone('!invalid!');
+       }
+
+       /**
+        * Tests setting valid timezone
+        */
+       public function testSettingValidDefaultTimezone () {
+               // Will be true
+               $this->assertTrue(FrameworkBootstrap::setDefaultTimezone('Europe/Berlin'));
+       }
+
+       /**
+        * Tests if detectServerAddress() is returning what it should for tests.
+        * This will always be 127.0.0.1.
+        */
+       public function testConfigDetectServerAddress () {
+               // Call it
+               $serverAddress = FrameworkBootstrap::detectServerAddress();
+
+               // Should be the same
+               $this->assertEquals(self::$ipAddress, $serverAddress);
+       }
+
+       /**
+        * Re-tests if detectServerAddress() is returning what it should for tests.
+        * This will always be 127.0.0.1. This call should not invoke
+        * ConsoleTools's method as the configuration entry is already cached.
+        */
+       public function testConfigDetectServerAddressCached () {
+               // Call it
+               $serverAddress = FrameworkBootstrap::detectServerAddress();
+
+               // Should be the same
+               $this->assertEquals(self::$ipAddress, $serverAddress);
+       }
+
+}
diff --git a/tests/framework/config/.htaccess b/tests/framework/config/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
index 329e01ca996b22359d3444e7a78959e7142393b9..4de7bbccd70c528dbdbb0f982c1cb0c78e83620b 100644 (file)
@@ -4,7 +4,6 @@
 namespace CoreFramework\Configuration;
 
 // Inport framework stuff
-use CoreFramework\Console\Tools\ConsoleTools;
 use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Generic\NullPointerException;
 use CoreFramework\Generic\UnsupportedOperationException;
@@ -32,7 +31,6 @@ use \InvalidArgumentException;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
 class FrameworkConfigurationTest extends TestCase {
 
        /**
@@ -40,11 +38,6 @@ class FrameworkConfigurationTest extends TestCase {
         */
        private static $configInstance = NULL;
 
-       /**
-        * Own IP address
-        */
-       private static $ipAddress = FALSE;
-
        /**
         * Setup test case
         */
@@ -79,12 +72,6 @@ class FrameworkConfigurationTest extends TestCase {
                 */
                ClassLoader::enableStrictNamingConventionCheck(FALSE);
 
-               // Quiet DNS resolver as this is not wanted here
-               self::$configInstance->setConfigEntry('quiet_dns_resolver', TRUE);
-
-               // Lookup own IP address
-               self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
-
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
@@ -662,249 +649,6 @@ class FrameworkConfigurationTest extends TestCase {
                self::$configInstance->unsetConfigEntry('__test_key');
        }
 
-       /**
-        * Tests setting a NULL default timezone
-        */
-       public function testSettingNullDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(NullPointerException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone(NULL);
-       }
-
-       /**
-        * Tests setting a boolean default timezone
-        */
-       public function testSettingBooleanDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone(FALSE);
-       }
-
-       /**
-        * Tests setting a decimal default timezone
-        */
-       public function testSettingDecimalDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone(12345);
-       }
-
-       /**
-        * Tests setting a float default timezone
-        */
-       public function testSettingFloatDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone(123.45);
-       }
-
-       /**
-        * Tests setting an array default timezone
-        */
-       public function testSettingArrayDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone(array());
-       }
-
-       /**
-        * Tests setting an object default timezone
-        */
-       public function testSettingObjectDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone($this);
-       }
-
-       /**
-        * Tests setting a resource default timezone
-        */
-       public function testSettingResourceDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Init some resource
-               $resource = fopen(__FILE__, 'r');
-
-               // Test it
-               self::$configInstance->setDefaultTimezone($resource);
-       }
-
-       /**
-        * Tests setting an empty default timezone
-        */
-       public function testSettingEmptyDefaultTimezone () {
-               // Will throw this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setDefaultTimezone('');
-       }
-
-       /**
-        * Tests setting invalid timezone
-        */
-       public function testSettingInvalidDefaultTimezone () {
-               // Expect Notice
-               $this->expectException(Notice::class);
-
-               // Try to set it
-               self::$configInstance->setDefaultTimezone('!invalid!');
-       }
-
-       /**
-        * Tests setting valid timezone
-        */
-       public function testSettingValidDefaultTimezone () {
-               // Will be true
-               $this->assertTrue(self::$configInstance->setDefaultTimezone('Europe/Berlin'));
-       }
-
-       /**
-        * Tests if detectServerAddress is returning what it should for tests.
-        * This will always be 127.0.0.1.
-        */
-       public function testConfigDetectServerAddress () {
-               // Call it
-               $serverAddress = self::$configInstance->detectServerAddress();
-
-               // Should be the same
-               $this->assertEquals(self::$ipAddress, $serverAddress);
-       }
-
-       /**
-        * Re-tests if detectServerAddress is returning what it should for tests.
-        * This will always be 127.0.0.1. This call should not invoke
-        * ConsoleTools's method as the configuration entry is already cached.
-        */
-       public function testConfigDetectServerAddressCached () {
-               // Call it
-               $serverAddress = self::$configInstance->detectServerAddress();
-
-               // Should be the same
-               $this->assertEquals(self::$ipAddress, $serverAddress);
-       }
-
-       /**
-        * Tests setting a NULL server address
-        */
-       public function testConfigSettingNullServerAddress () {
-               // Expect this exception
-               $this->expectException(NullPointerException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress(NULL);
-       }
-
-       /**
-        * Tests setting a boolean server address
-        */
-       public function testConfigSettingBooleanServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress(FALSE);
-       }
-
-       /**
-        * Tests setting a decimal server address
-        */
-       public function testConfigSettingDecimalServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress(12345);
-       }
-
-       /**
-        * Tests setting a float server address
-        */
-       public function testConfigSettingFloatServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress(123.45);
-       }
-
-       /**
-        * Tests setting an array server address
-        */
-       public function testConfigSettingArrayServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress(array());
-       }
-
-       /**
-        * Tests setting an object server address
-        */
-       public function testConfigSettingObjectServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress($this);
-       }
-
-       /**
-        * Tests setting a resource server address
-        */
-       public function testConfigSettingResourceServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Init some resource
-               $resource = fopen(__FILE__, 'r');
-
-               // Test it
-               self::$configInstance->setServerAddress($resource);
-       }
-
-       /**
-        * Tests setting an empty server address
-        */
-       public function testConfigSettingEmptyServerAddress () {
-               // Expect this exception
-               $this->expectException(InvalidArgumentException::class);
-
-               // Test it
-               self::$configInstance->setServerAddress('');
-       }
-
-       /**
-        * Tests setting a valid server address and getting it back
-        */
-       public function testConfigGettingValidServerAddress () {
-               // Test it
-               self::$configInstance->setServerAddress('127.0.0.1');
-
-               // Get it back
-               $serverAddress = self::$configInstance->getServerAddress();
-
-               // Should be equal
-               $this->assertEquals('127.0.0.1', $serverAddress);
-
-               // Set old back
-               self::$configInstance->setServerAddress(self::$ipAddress);
-       }
-
        /**
         * Tests if the method getField() is still unsupported in this class. Please
         * note, that this and isFieldSet() may get removed in the future. So also