| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/* Some utility functions for the test scripts */
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* this is used (with array filter) to filter out the test*
|
|
|
7 |
* methods from a PHPUnit testcase
|
|
|
8 |
*/
|
|
|
9 |
function grepForTest($var)
|
|
|
10 |
{
|
|
|
11 |
return preg_match('/\btest.*/', $var);
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* given a class name it returns an array of test* methods
|
|
|
16 |
*
|
|
|
17 |
* @param $class text classname
|
|
|
18 |
* @return array of methods beginning with test
|
|
|
19 |
*/
|
|
|
20 |
function getTests($class)
|
|
|
21 |
{
|
|
|
22 |
$methods = array_map('strtolower', get_class_methods($class));
|
|
|
23 |
return array_filter($methods, 'grepForTest');
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Little helper function that outputs check for boxes with suitable names
|
|
|
28 |
*/
|
|
|
29 |
function testCheck($testcase, $testmethod)
|
|
|
30 |
{
|
|
|
31 |
return "<input type=\"checkbox\" name=\"testmethods[$testcase][$testmethod]\" value=\"1\">$testmethod <br>\n";
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Little helper function that gets a backtrace if available
|
|
|
36 |
*/
|
|
|
37 |
function getBacktrace($errline = 0)
|
|
|
38 |
{
|
|
|
39 |
$message = '';
|
|
|
40 |
if (!function_exists('debug_backtrace')) {
|
|
|
41 |
$message.= 'function debug_backtrace does not exists'."\n";
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
$debug_backtrace = debug_backtrace();
|
|
|
45 |
array_shift($debug_backtrace);
|
|
|
46 |
$message.= 'Debug backtrace:'."\n";
|
|
|
47 |
|
|
|
48 |
foreach ($debug_backtrace as $trace_item) {
|
|
|
49 |
$message.= "\t" . ' @ ';
|
|
|
50 |
if (!empty($trace_item['file'])) {
|
|
|
51 |
$message.= basename($trace_item['file']) . ':' . $trace_item['line'];
|
|
|
52 |
} else {
|
|
|
53 |
$message.= '- PHP inner-code - ';
|
|
|
54 |
}
|
|
|
55 |
$message.= ' -- ';
|
|
|
56 |
if (!empty($trace_item['class'])) {
|
|
|
57 |
$message.= $trace_item['class'] . $trace_item['type'];
|
|
|
58 |
}
|
|
|
59 |
$message.= $trace_item['function'];
|
|
|
60 |
|
|
|
61 |
if (!empty($trace_item['args']) && is_array($trace_item['args'])) {
|
|
|
62 |
$args = array();
|
|
|
63 |
foreach ($trace_item['args'] as $arg) {
|
|
|
64 |
$args[] = is_scalar($arg) ? $arg : (is_object($arg) ? get_class($arg) : gettype($arg));
|
|
|
65 |
}
|
|
|
66 |
$message.= '('.implode(', ', $args).')';
|
|
|
67 |
} else {
|
|
|
68 |
$message.= '()';
|
|
|
69 |
}
|
|
|
70 |
$message.= "\n";
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
return $message;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
require_once 'PEAR.php';
|
|
|
77 |
function errorHandlerPEAR($error_obj)
|
|
|
78 |
{
|
|
|
79 |
$message = "-- PEAR-Error --\n";
|
|
|
80 |
$message.= $error_obj->getMessage().': '.$error_obj->getUserinfo()."\n";
|
|
|
81 |
$message.= getBacktrace();
|
|
|
82 |
|
|
|
83 |
print_r($message);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandlerPEAR');
|
|
|
87 |
|
|
|
88 |
$GLOBALS['_show_silenced'] = false;
|
|
|
89 |
function errorHandler($errno, $errstr, $errfile, $errline)
|
|
|
90 |
{
|
|
|
91 |
if ((!$GLOBALS['_show_silenced'] && !error_reporting()) || $errno == 2048) {
|
|
|
92 |
return;
|
|
|
93 |
}
|
|
|
94 |
$message = "\n";
|
|
|
95 |
switch ($errno) {
|
|
|
96 |
case E_USER_ERROR:
|
|
|
97 |
$message.= "FATAL [$errno] $errstr\n";
|
|
|
98 |
$message.= " Fatal error in line $errline of file $errfile";
|
|
|
99 |
$message.= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
|
|
|
100 |
$message.= "Aborting...\n";
|
|
|
101 |
die($message);
|
|
|
102 |
break;
|
|
|
103 |
case E_USER_WARNING:
|
|
|
104 |
$message.= "ERROR [$errno] $errstr in line $errline of file $errfile\n";
|
|
|
105 |
break;
|
|
|
106 |
case E_USER_NOTICE:
|
|
|
107 |
$message.= "WARNING [$errno] $errstr in line $errline of file $errfile\n";
|
|
|
108 |
break;
|
|
|
109 |
default:
|
|
|
110 |
$message.= "Unkown error type: [$errno] $errstr in line $errline of file $errfile\n";
|
|
|
111 |
break;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
$message.= getBacktrace($errline);
|
|
|
115 |
|
|
|
116 |
print_r($message);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
set_error_handler('errorHandler');
|
|
|
120 |
if (function_exists('xdebug_disable')) {
|
|
|
121 |
xdebug_disable();
|
|
|
122 |
}
|
|
|
123 |
?>
|