2 // Import framework stuff
3 use CoreFramework\Object\BaseFrameworkSystem;
6 * An include file for setting up the exception handler of test suite
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 // The node's own exception handler
28 function tests_exception_handler ($exceptionInstance) {
29 // Is it an object and a valid instance?
30 if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
34 // Get all call levels from backtrace
35 foreach ($exceptionInstance->getTrace() as $idx => $traceArray) {
36 // Init argument string
39 // Convert arguments type into human-readable
40 foreach ($traceArray['args'] as $arg) {
41 $argsString .= ', ' . gettype($arg);
43 $argsString = substr($argsString, 2);
45 // Set missing file/line
46 if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';
47 if (!isset($traceArray['line'])) $traceArray['line'] = '0';
48 if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
49 if (!isset($traceArray['type'])) $traceArray['type'] = '->';
51 $backTrace .= sprintf("---------- Pos %d: ----------
59 $traceArray['function'],
61 basename($traceArray['file']),
66 // Construct the message
67 $message = sprintf("--------------------------------------------------------------------------------
68 Uncaught Exception : %s
69 --------------------------------------------------------------------------------
74 --------------------------------------------------------------------------------
76 --------------------------------------------------------------------------------
78 --------------------------------------------------------------------------------\n",
79 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
80 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
81 $exceptionInstance->getHexCode(),
82 $exceptionInstance->getFile(),
83 $exceptionInstance->getLine(),
90 // Invalid exception instance detected! Do *only* throw exceptions that
91 // extends our own exception 'FrameworkException' to get such nice
92 // outputs like above.
93 print('exceptionInstance[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.' . PHP_EOL);
98 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
99 // Construct the message
100 $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s',
107 // Throw an exception here
108 throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
112 function __assertHandler ($file, $line, $code) {
115 $code = '<em>Unknown</em>';
119 $message = sprintf('File: %s, Line: %s, Code: %s',
126 syslog(LOG_WARNING, $message);
128 // Throw an exception here
129 throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
133 //set_error_handler('__errorHandler');
135 // Set the new handler
136 set_exception_handler('tests_exception_handler');
138 // Init assert handling
139 assert_options(ASSERT_ACTIVE , TRUE);
140 assert_options(ASSERT_WARNING , FALSE);
141 assert_options(ASSERT_BAIL , TRUE);
142 assert_options(ASSERT_QUIET_EVAL, FALSE);
143 assert_options(ASSERT_CALLBACK , '__assertHandler');