Source for file errors.php
Documentation is available at errors.php
* base include file for SimpleTest
* @version $Id: errors.php 1672 2008-03-02 04:47:34Z edwardzyang $
* @ignore - PHP5 compatibility fix.
* Includes SimpleTest files.
require_once dirname(__FILE__
) .
'/invoker.php';
require_once dirname(__FILE__
) .
'/test_case.php';
require_once dirname(__FILE__
) .
'/expectation.php';
* Extension that traps errors into an error queue.
* Stores the invoker to wrap.
* @param SimpleInvoker $invoker Test method runner.
* Invokes a test method and dispatches any
* untrapped errors. Called back from
* @param string $method Test method to call.
$queue =
&$this->_createErrorQueue();
* Wires up the error queue for a single test.
* @return SimpleErrorQueue Queue connected to the test.
function &_createErrorQueue() {
$queue =
&$context->get('SimpleErrorQueue');
$queue->setTestCase($test);
* Error queue used to record trapped
* Starts with an empty queue.
* Discards the contents of the error queue.
* Sets the currently running test case.
* @param SimpleTestCase $test Test case to send messages to.
* Sets up an expectation of an error. If this is
* not fulfilled at the end of the test, a failure
* will occour. If the error does happen, then this
* will cancel it out and send a pass message.
* @param SimpleExpectation $expected Expected error match.
* @param string $message Message to display.
* Adds an error to the front of the queue.
* @param integer $severity PHP error code.
* @param string $content Text of error.
* @param string $filename File error occoured in.
* @param integer $line Line number of error.
function add($severity, $content, $filename, $line) {
$this->_testLatestError($severity, $content, $filename, $line);
array($severity, $content, $filename, $line));
* Any errors still in the queue are sent to the test
* case. Any unfulfilled expectations trigger failures.
while (list
($severity, $message, $file, $line) =
$this->extract()) {
$this->_test->error($severity, $message, $file, $line);
while (list
($expected, $message) =
$this->_extractExpectation()) {
$this->_test->assert($expected, false, "%s -> Expected error not caught");
* Tests the error against the most recent expected
* @param integer $severity PHP error code.
* @param string $content Text of error.
* @param string $filename File error occoured in.
* @param integer $line Line number of error.
function _testLatestError($severity, $content, $filename, $line) {
if ($expectation =
$this->_extractExpectation()) {
list
($expected, $message) =
$expectation;
"%s -> PHP error [$content] severity [" .
"] in [$filename] line [$line]"));
$this->_test->error($severity, $content, $filename, $line);
* Pulls the earliest error from the queue.
* @return mixed 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.
* Pulls the earliest expectation from the queue.
* @return SimpleExpectation False if none.
function _extractExpectation() {
return $this->_test->assert(
sprintf($message, 'Should be no errors'));
$this->_test->fail(sprintf($message, 'Expected error not found'));
list
($severity, $content, $file, $line) =
$this->extract();
return $this->_test->assert(
sprintf($message, "Expected PHP error [$content] severity [$severity] in [$file] line [$line]"));
* Converts an error code into it's string
* @param $severity PHP integer error code.
* @return String version of error code.
E_WARNING =>
'E_WARNING',
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');
if (defined('E_RECOVERABLE_ERROR')) {
$map[E_RECOVERABLE_ERROR] =
'E_RECOVERABLE_ERROR';
if (defined('E_DEPRECATED')) {
$map[E_DEPRECATED] =
'E_DEPRECATED';
* 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.
function SimpleTestErrorHandler($severity, $message, $filename =
null, $line =
null, $super_globals =
null, $mask =
null) {
error_log("$label: $message in $filename on line $line");
$queue =
&$context->get('SimpleErrorQueue');
$queue->add($severity, $message, $filename, $line);
Documentation generated on Sun, 04 May 2008 09:21:32 -0500 by phpDocumentor 1.3.0