summaryrefslogtreecommitdiff
path: root/tests/test_tools/simpletest/errors.php
diff options
context:
space:
mode:
authorwei <>2006-07-07 23:18:19 +0000
committerwei <>2006-07-07 23:18:19 +0000
commitb2e97539e7af7712b04dd5c2610a454d09aa0333 (patch)
treed09ae76ddc7f349a39b74b0cb1f40c8b678a352e /tests/test_tools/simpletest/errors.php
parentfce10eed76455b7e0419f13affb4f29e73ef0375 (diff)
Update simpletest
Diffstat (limited to 'tests/test_tools/simpletest/errors.php')
-rw-r--r--tests/test_tools/simpletest/errors.php67
1 files changed, 54 insertions, 13 deletions
diff --git a/tests/test_tools/simpletest/errors.php b/tests/test_tools/simpletest/errors.php
index 70c6c338..0608de60 100644
--- a/tests/test_tools/simpletest/errors.php
+++ b/tests/test_tools/simpletest/errors.php
@@ -3,13 +3,54 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id: errors.php,v 1.13 2005/01/08 03:48:39 lastcraft Exp $
+ * @version $Id: errors.php,v 1.14 2006/02/06 06:05:18 lastcraft Exp $
*/
+
/** @ignore - PHP5 compatibility fix. */
if (! defined('E_STRICT')) {
define('E_STRICT', 2048);
}
-
+
+ /**#@+
+ * Includes SimpleTest files.
+ */
+ require_once(dirname(__FILE__) . '/invoker.php');
+
+ /**
+ * Extension that traps errors into an error queue.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+ class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator {
+
+ /**
+ * Stores the invoker to wrap.
+ * @param SimpleInvoker $invoker Test method runner.
+ */
+ function SimpleErrorTrappingInvoker($invoker) {
+ $this->SimpleInvokerDecorator($invoker);
+ }
+
+ /**
+ * Invokes a test method and dispatches any
+ * untrapped errors. Called back from
+ * the visiting runner.
+ * @param string $method Test method to call.
+ * @access public
+ */
+ function invoke($method) {
+ set_error_handler('simpleTestErrorHandler');
+ parent::invoke($method);
+ $queue = &SimpleErrorQueue::instance();
+ while (list($severity, $message, $file, $line, $globals) = $queue->extract()) {
+ $severity = SimpleErrorQueue::getSeverityAsString($severity);
+ $test_case = $this->getTestCase();
+ $test_case->error($severity, $message, $file, $line);
+ }
+ restore_error_handler();
+ }
+ }
+
/**
* Singleton error queue used to record trapped
* errors.
@@ -18,7 +59,7 @@
*/
class SimpleErrorQueue {
protected $_queue;
-
+
/**
* Starts with an empty queue.
* @access public
@@ -26,7 +67,7 @@
function SimpleErrorQueue() {
$this->clear();
}
-
+
/**
* Adds an error to the front of the queue.
* @param $severity PHP error code.
@@ -41,7 +82,7 @@
$this->_queue,
array($severity, $message, $filename, $line, $super_globals));
}
-
+
/**
* Pulls the earliest error from the queue.
* @return False if none, or a list of error
@@ -57,7 +98,7 @@
}
return false;
}
-
+
/**
* Discards the contents of the error queue.
* @access public
@@ -65,7 +106,7 @@
function clear() {
$this->_queue = array();
}
-
+
/**
* Tests to see if the queue is empty.
* @return True if empty.
@@ -73,21 +114,21 @@
function isEmpty() {
return (count($this->_queue) == 0);
}
-
+
/**
* Global access to a single error queue.
* @return Global error queue object.
* @access public
* @static
*/
- static function instance() {
+ function &instance() {
static $queue = false;
if (! $queue) {
$queue = new SimpleErrorQueue();
}
return $queue;
}
-
+
/**
* Converst an error code into it's string
* representation.
@@ -96,7 +137,7 @@
* @access public
* @static
*/
- static function getSeverityAsString($severity) {
+ function getSeverityAsString($severity) {
static $map = array(
E_STRICT => 'E_STRICT',
E_ERROR => 'E_ERROR',
@@ -113,7 +154,7 @@
return $map[$severity];
}
}
-
+
/**
* Error handler that simply stashes any errors into the global
* error queue. Simulates the existing behaviour with respect to
@@ -133,7 +174,7 @@
$label = SimpleErrorQueue::getSeverityAsString($severity);
error_log("$label: $message in $filename on line $line");
}
- $queue = SimpleErrorQueue::instance();
+ $queue = &SimpleErrorQueue::instance();
$queue->add($severity, $message, $filename, $line, $super_globals);
set_error_handler('simpleTestErrorHandler');
}