<?php
-/**
- * Application data
- *
- * Please remember that this include file is being loaded *before* the class
- * loader is loading classes from "exceptions", "interfaces" and "main"!
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-
-// 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
*/
// 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
// 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';
}
// 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,
}
// 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 = '<em>Unknown</em>';
}
}
// 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');
<?php
-/**
- * The application's class loader
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-
-// Scan for application's classes, exceptions and interfaces
-ClassLoader::scanApplicationClasses();
+// @DEPRECATED
<?php
-/**
- * The application launcher
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-
-// 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 <span class=\"app_name\">%s</span> could not be launched because the helper class <span class=\"class_name\">%s</span> is not loaded.",
- $application,
- FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class')
- ));
-} elseif (!is_object($app)) {
- // No object!
- ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> 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 <span class=\"app_name\">%s</span> could not be launched because the method <span class=\"method_name\">%s</span> is missing.",
- $application,
- FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')
- ));
-}
-
-// Call user function
-call_user_func_array(array($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')), []);
+// @DEPRECATED
// Import SPL stuff
use \InvalidArgumentException;
+use \UnexpectedValueException;
/*
* Copyright (C) 2017 - 2020 - Core Developer Team
$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')));
+ }
+
}