2005-06-18 23:26:35 +00:00
|
|
|
<?php
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* base include file for SimpleTest
|
|
|
|
* @package SimpleTest
|
|
|
|
* @subpackage UnitTester
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
/** @ignore - PHP5 compatibility fix. */
|
2005-06-18 23:26:35 +00:00
|
|
|
if (! defined('E_STRICT')) {
|
|
|
|
define('E_STRICT', 2048);
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Singleton error queue used to record trapped
|
|
|
|
* errors.
|
|
|
|
* @package SimpleTest
|
|
|
|
* @subpackage UnitTester
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
class SimpleErrorQueue {
|
|
|
|
var $_queue;
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Starts with an empty queue.
|
|
|
|
* @access public
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function SimpleErrorQueue() {
|
|
|
|
$this->clear();
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Adds an error to the front of the queue.
|
|
|
|
* @param $severity PHP error code.
|
|
|
|
* @param $message Text of error.
|
|
|
|
* @param $filename File error occoured in.
|
|
|
|
* @param $line Line number of error.
|
|
|
|
* @param $super_globals Hash of PHP super global arrays.
|
|
|
|
* @access public
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function add($severity, $message, $filename, $line, $super_globals) {
|
|
|
|
array_push(
|
|
|
|
$this->_queue,
|
|
|
|
array($severity, $message, $filename, $line, $super_globals));
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Pulls the earliest error from the queue.
|
|
|
|
* @return False if none, or a list of error
|
|
|
|
* information. Elements are: severity
|
|
|
|
* as the PHP error code, the error message,
|
|
|
|
* the file with the error, the line number
|
|
|
|
* and a list of PHP super global arrays.
|
|
|
|
* @access public
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function extract() {
|
|
|
|
if (count($this->_queue)) {
|
|
|
|
return array_shift($this->_queue);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Discards the contents of the error queue.
|
|
|
|
* @access public
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function clear() {
|
|
|
|
$this->_queue = array();
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Tests to see if the queue is empty.
|
|
|
|
* @return True if empty.
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function isEmpty() {
|
|
|
|
return (count($this->_queue) == 0);
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Global access to a single error queue.
|
|
|
|
* @return Global error queue object.
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function &instance() {
|
|
|
|
static $queue = false;
|
|
|
|
if (! $queue) {
|
|
|
|
$queue = new SimpleErrorQueue();
|
|
|
|
}
|
|
|
|
return $queue;
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Converst an error code into it's string
|
|
|
|
* representation.
|
|
|
|
* @param $severity PHP integer error code.
|
|
|
|
* @return String version of error code.
|
|
|
|
* @access public
|
|
|
|
* @static
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function getSeverityAsString($severity) {
|
|
|
|
static $map = array(
|
|
|
|
E_STRICT => 'E_STRICT',
|
|
|
|
E_ERROR => 'E_ERROR',
|
|
|
|
E_WARNING => 'E_WARNING',
|
|
|
|
E_PARSE => 'E_PARSE',
|
|
|
|
E_NOTICE => 'E_NOTICE',
|
|
|
|
E_CORE_ERROR => 'E_CORE_ERROR',
|
|
|
|
E_CORE_WARNING => 'E_CORE_WARNING',
|
|
|
|
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
|
|
|
|
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
|
|
|
|
E_USER_ERROR => 'E_USER_ERROR',
|
|
|
|
E_USER_WARNING => 'E_USER_WARNING',
|
|
|
|
E_USER_NOTICE => 'E_USER_NOTICE');
|
|
|
|
return $map[$severity];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Error handler that simply stashes any errors into the global
|
|
|
|
* error queue. Simulates the existing behaviour with respect to
|
|
|
|
* logging errors, but this feature may be removed in future.
|
|
|
|
* @param $severity PHP error code.
|
|
|
|
* @param $message Text of error.
|
|
|
|
* @param $filename File error occoured in.
|
|
|
|
* @param $line Line number of error.
|
|
|
|
* @param $super_globals Hash of PHP super global arrays.
|
|
|
|
* @static
|
|
|
|
* @access public
|
|
|
|
*/
|
2005-06-18 23:26:35 +00:00
|
|
|
function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) {
|
|
|
|
if ($severity = $severity & error_reporting()) {
|
|
|
|
restore_error_handler();
|
|
|
|
if (ini_get('log_errors')) {
|
|
|
|
$label = SimpleErrorQueue::getSeverityAsString($severity);
|
|
|
|
error_log("$label: $message in $filename on line $line");
|
|
|
|
}
|
|
|
|
$queue = &SimpleErrorQueue::instance();
|
|
|
|
$queue->add($severity, $message, $filename, $line, $super_globals);
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|