From: Roland Häder Date: Sun, 16 Jul 2017 15:02:28 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=060297c0efcdcfab4935d6eee825cd376c318ef4;p=core.git Continued a bit: - some rewrites to make PHPUnit be able to unit-test it - more sanity-checks on parameters, were sometimes combined - surpress some anoyances caused by to strict xdebug settings Signed-off-by: Roland Häder --- diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index aa29d572..0e7f4dc6 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -1,7 +1,6 @@ =')) { - /* - * Set desired time zone to prevent date() and related functions to - * issue a E_WARNING. - */ - date_default_timezone_set($zone); - } // END - if + // 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; } /** @@ -164,14 +170,17 @@ class FrameworkConfiguration implements Registerable { // Is it null? if (is_null($configKey)) { // Throw NPE - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_string($configKey)) { + // Is not a string + throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } elseif (empty($configKey)) { // Entry is empty throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } // Is it set? - $isset = isset($this->config[$configKey]); + $isset = ((isset($this->config[$configKey])) || (array_key_exists($configKey, $this->config))); // Return the result return $isset; @@ -190,7 +199,10 @@ class FrameworkConfiguration implements Registerable { // Is it null? if (is_null($configKey)) { // Throw NPE - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_string($configKey)) { + // Is not a string + throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } elseif (empty($configKey)) { // Entry is empty throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); @@ -217,19 +229,22 @@ class FrameworkConfiguration implements Registerable { * @return void * @throws NullPointerException If $configKey is NULL * @throws InvalidArgumentException If $configKey is empty - * @throws ConfigValueTypeUnsupportedException If $configValue has an unsupported variable type + * @throws InvalidArgumentException If $configValue has an unsupported variable type */ public final function setConfigEntry ($configKey, $configValue) { // Is a valid configuration key key provided? if (is_null($configKey)) { // Configuration key is null - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif ((empty($configKey)) || (!is_string($configKey))) { + throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_string($configKey)) { + // Is not a string + throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } elseif (empty($configKey)) { // Entry is empty throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); - } elseif ((is_null($configValue)) || (is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) { + } elseif ((is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) { // These cannot be set as this is not intended for configuration values, please use FrameworkArrayObject instead. - throw new ConfigValueTypeUnsupportedException(array($this, $configKey, $configValue), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED); + throw new InvalidArgumentException(sprintf('configValue[]=%s for configKey=%s is not supported.', gettype($configValue), $configKey), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED); } // Cast to string @@ -264,10 +279,14 @@ class FrameworkConfiguration implements Registerable { * @throws NoConfigEntryException If a configuration element was not found */ public final function unsetConfigEntry ($configKey) { + // Validate parameters if (is_null($configKey)) { // Configuration key is null - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif ((empty($configKey)) || (!is_string($configKey))) { + throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_string($configKey)) { + // Entry is empty + throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } elseif (empty($configKey)) { // Entry is empty throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } @@ -334,6 +353,19 @@ class FrameworkConfiguration implements Registerable { * @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 (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); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 35eb2b2a..3d2f1aee 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,5 +32,11 @@ require dirname(__DIR__) . '/index.php'; // Remove it to prevent leak to PHPUnit unset($_SERVER['argv'][1]); +// For these unit tests, xdebug must be quieted a bit +if (extension_loaded('xdebug')) { + // Quiet it a bit as this interfers with the nice testing output + ini_set('xdebug.show_exception_trace', FALSE); +} // END - if + // Autoload more stuff require dirname(__DIR__) . '/vendor/autoload.php';