From: Roland Häder Date: Fri, 17 Feb 2023 01:34:39 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c4f117ca17646bdcb16989c28f913638ccb6cc30;p=core.git Continued: - deprecated no longer needed files (they are deprecated to use anyway) - added unit tests for FrameworkConfiguration->isEnabled() method --- diff --git a/application/tests/data.php b/application/tests/data.php index 6c0572b0..7d6dceec 100644 --- a/application/tests/data.php +++ b/application/tests/data.php @@ -1,40 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.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 . - */ - -// Get config instance -$cfg = FrameworkConfiguration::getSelfInstance(); - -// Get an instance of the helper -$app = call_user_func_array( - array($cfg->getConfigEntry('app_helper_class'), 'getSelfInstance'), - [] -); - -// Set application name and version -$app->setAppName('Unit tests and more'); -$app->setAppVersion('0.0.0'); -$app->setAppShortName('tests'); +// @DEPRECATED diff --git a/application/tests/exceptions.php b/application/tests/exceptions.php index 1e960cb8..251765e5 100644 --- a/application/tests/exceptions.php +++ b/application/tests/exceptions.php @@ -28,7 +28,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; */ // The node's own exception handler -function tests_exception_handler ($exceptionInstance) { +function core_exception_handler ($exceptionInstance) { // Is it an object and a valid instance? if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof Exception)) { // Init variable @@ -39,11 +39,14 @@ function tests_exception_handler ($exceptionInstance) { // Init argument string $argsString = ''; - // Convert arguments type into human-readable - foreach ($traceArray['args'] as $arg) { - $argsString .= ', ' . gettype($arg); + // Arguments given? + if (isset($traceArray['args'])) { + // Convert arguments type into human-readable + foreach ($traceArray['args'] as $arg) { + $argsString .= ', ' . gettype($arg); + } + $argsString = substr($argsString, 2); } - $argsString = substr($argsString, 2); // Set missing file/line if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown'; @@ -103,9 +106,9 @@ Backtrace: } // Error handler -function tests_error_handler ($errno, $errstr, $errfile, $errline, array $errcontext) { +function core_error_handler (int $errno, string $errstr, string $errfile, int $errline, array $errcontext) { // Construct the message - $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s', + $message = sprintf('File: %s, Line: %d, Code: %d, Message: %s', basename($errfile), $errline, $errno, @@ -117,9 +120,9 @@ function tests_error_handler ($errno, $errstr, $errfile, $errline, array $errcon } // Assertion handler -function tests_assert_handler (string $file, int $line, $code) { +function core_assert_handler (string $file, int $line, int $code) { // Empty code? - if ($code === '') { + if (empty($code)) { $code = 'Unknown'; } @@ -138,14 +141,14 @@ function tests_assert_handler (string $file, int $line, $code) { } // Set error handler -//set_error_handler('tests_error_handler'); +//set_error_handler('core_error_handler'); // Set the new handler -set_exception_handler('tests_exception_handler'); +set_exception_handler('core_exception_handler'); // Init assert handling assert_options(ASSERT_ACTIVE , true); -assert_options(ASSERT_WARNING , false); +assert_options(ASSERT_WARNING , true); assert_options(ASSERT_BAIL , true); assert_options(ASSERT_QUIET_EVAL, false); -assert_options(ASSERT_CALLBACK , 'tests_assert_handler'); +assert_options(ASSERT_CALLBACK , 'core_assert_handler'); diff --git a/application/tests/loader.php b/application/tests/loader.php index d863d21a..7d6dceec 100644 --- a/application/tests/loader.php +++ b/application/tests/loader.php @@ -1,25 +1,2 @@ - * @version 0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 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 . - */ - -// Scan for application's classes, exceptions and interfaces -ClassLoader::scanApplicationClasses(); +// @DEPRECATED diff --git a/application/tests/starter.php b/application/tests/starter.php index ddab3daa..7d6dceec 100644 --- a/application/tests/starter.php +++ b/application/tests/starter.php @@ -1,54 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.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 . - */ - -// Is there an application helper instance? We need the method main() for -// maining the application -$app = call_user_func_array( - array( - FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class'), 'getSelfInstance' - ), [] -); - -// Some sanity checks -if ((empty($app)) || (is_null($app))) { - // Something went wrong! - ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the helper class %s is not loaded.", - $application, - FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class') - )); -} elseif (!is_object($app)) { - // No object! - ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because 'app' is not an object.", - $application - )); -} elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) { - // Method not found! - ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the method %s is missing.", - $application, - FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method') - )); -} - -// Call user function -call_user_func_array(array($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')), []); +// @DEPRECATED diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index fb65b3f8..27fdc26b 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; // Import SPL stuff use \InvalidArgumentException; +use \UnexpectedValueException; /* * Copyright (C) 2017 - 2020 - Core Developer Team @@ -349,4 +350,48 @@ class FrameworkConfigurationTest extends TestCase { $dummy = self::$configInstance->isFieldSet('foo'); } + /** + * Tests isEnabled() method being called with empty parameter + */ + public function testConfigIsEnabledEmptyString () { + // Expect IAE + $this->expectException(InvalidArgumentException::class); + + // Just invoke it + $dummy = self::$configInstance->isEnabled(''); + } + + /** + * Tests isEnabled() method being called with missing configuration key + */ + public function testConfigIsEnabledMissingConfigKey () { + // Expect NoConfig + $this->expectException(NoConfigEntryException::class); + + // Just invoke it + $dummy = self::$configInstance->isEnabled('does_not_exist'); + } + + /** + * Tests isEnabled() method being called with non-boolean configuration key + */ + public function testConfigIsEnabledNonBooleanConfigKey () { + // Expect UVE + $this->expectException(UnexpectedValueException::class); + + // Set it temporary + self::$configInstance->setConfigEntry('is_non_boolean_enabled', 'Y'); + + // Just invoke it + $dummy = self::$configInstance->isEnabled('non_boolean'); + } + + /** + * Tests isEnabled() method being called with 'single_server' + */ + public function testConfigIsEnabledSingleServerConfigKey () { + // Check it on known boolean value + $this->assertTrue(is_bool(self::$configInstance->isEnabled('single_server'))); + } + }