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;
// Import SPL stuff
use \BadMethodCallException;
+use \InvalidArgumentException;
/**
* A framework-bootstrap class which helps the frameworks to bootstrap ... ;-)
*/
final class FrameworkBootstrap {
+ /**
+ * Detected server address
+ */
+ private static $serverAddress = NULL;
+
/**
* Instance of a Requestable class
*/
$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
$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');
// 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_');
$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');
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
*
}
// Convert dashes to underscore
- $configKey = self::convertDashesToUnderscores($configKey);
+ $configKey = $this->convertDashesToUnderscores($configKey);
// Is a valid configuration key provided?
if (!$this->isConfigurationEntrySet($configKey)) {
}
// 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);
}
// Convert dashes to underscore
- $configKey = self::convertDashesToUnderscores($configKey);
+ $configKey = $this->convertDashesToUnderscores($configKey);
// Is the configuration key there?
if (!$this->isConfigurationEntrySet($configKey)) {
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
*
namespace CoreFramework\Crypto\RandomNumber;
// Import framework stuff
+use CoreFramework\Bootstrap\FrameworkBootstrap;
use CoreFramework\Object\BaseFrameworkSystem;
use CoreFramework\Generic\FrameworkInterface;
// 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
));
}
- // Set it in configuration
- FrameworkConfiguration::getSelfInstance()->setServerAddress($ipAddress);
-
// Return it
return $ipAddress;
}
* @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);
<?php
+// Import needed stuff
+use CoreFramework\Configuration\FrameworkConfiguration;
+
/*
* Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
*
// 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);
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?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);
+ }
+
+}
--- /dev/null
+Deny from all
namespace CoreFramework\Configuration;
// Inport framework stuff
-use CoreFramework\Console\Tools\ConsoleTools;
use CoreFramework\Loader\ClassLoader;
use CoreFramework\Generic\NullPointerException;
use CoreFramework\Generic\UnsupportedOperationException;
* 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 {
/**
*/
private static $configInstance = NULL;
- /**
- * Own IP address
- */
- private static $ipAddress = FALSE;
-
/**
* Setup test case
*/
*/
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__);
}
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