コード例 #1
0
ファイル: errors_test.php プロジェクト: Clansuite/Clansuite
 public function testExpectationMatchCancelsIncomingError()
 {
     $test = new MockSimpleTestCase();
     $test->expectOnce('assert', array(new IdenticalExpectation(new AnythingExpectation()), 'B', 'a message'));
     $test->setReturnValue('assert', true);
     $test->expectNever('error');
     $queue = new SimpleErrorQueue();
     $queue->setTestCase($test);
     $queue->expectError(new AnythingExpectation(), 'a message');
     $queue->add(1024, 'B', 'b.php', 100);
 }
コード例 #2
0
 function testTrappedErrorPLacedInQueue() {
     $queue = &SimpleErrorQueue::instance();
     $this->assertFalse($queue->extract());
     trigger_error('Ouch!');
     list($severity, $message, $file, $line, $globals) = $queue->extract();
     $this->assertEqual($message, 'Ouch!');
     $this->assertEqual($file, __FILE__);
     $this->assertFalse($queue->extract());
 }
コード例 #3
0
 function invoke($method)
 {
     set_error_handler('simpleTestErrorHandler');
     parent::invoke($method);
     $queue =& SimpleErrorQueue::instance();
     while (list($severity, $message, $file, $line, $globals) = $queue->extract()) {
         $test_case =& $this->getTestCase();
         $test_case->error($severity, $message, $file, $line, $globals);
     }
     restore_error_handler();
 }
コード例 #4
0
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');
    }
}
コード例 #5
0
ファイル: errors.php プロジェクト: JackCanada/moodle-hacks
 /**
  *    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)
 {
     $context =& SimpleTest::getContext();
     $queue =& $context->get('SimpleErrorQueue');
     $queue->setTestCase($this->GetTestCase());
     set_error_handler('SimpleTestErrorHandler');
     parent::invoke($method);
     while (list($severity, $message, $file, $line) = $queue->extract()) {
         $severity = SimpleErrorQueue::getSeverityAsString($severity);
         $test =& $this->getTestCase();
         $test->error($severity, $message, $file, $line);
     }
     restore_error_handler();
 }
コード例 #6
0
 function swallowErrors()
 {
     $queue =& SimpleErrorQueue::instance();
     $queue->clear();
 }
コード例 #7
0
ファイル: unit_tester.php プロジェクト: justinlyon/scc
 /**
  *    Confirms that an error has occoured and
  *    that the error text matches a Perl regular
  *    expression.
  *    @param string $expected   Perl regular expresion to
  *                              match against.
  *    @param string $message    Message to display.
  *    @return boolean           True on pass
  *    @access public
  */
 function assertErrorPattern($pattern, $message = "%s")
 {
     $queue =& SimpleErrorQueue::instance();
     if ($queue->isEmpty()) {
         $this->fail(sprintf($message, "Expected error not found"));
         return;
     }
     list($severity, $content, $file, $line, $globals) = $queue->extract();
     $severity = SimpleErrorQueue::getSeverityAsString($severity);
     return $this->assertTrue((bool) preg_match($pattern, $content), "Expected pattern match [{$pattern}] in PHP error [{$content}] severity [{$severity}] in [{$file}] line [{$line}]");
 }
コード例 #8
0
ファイル: unit_tester.php プロジェクト: TomMaher/umambo
 /**
  *    Confirms that an error has occoured and
  *    optionally that the error text matches exactly.
  *    @param string $expected   Expected error text or
  *                              false for no check.
  *    @param string $message    Message to display.
  *    @return boolean           True on pass
  *    @access public
  */
 function assertError($expected = false, $message = "%s")
 {
     $queue =& SimpleErrorQueue::instance();
     if ($queue->isEmpty()) {
         $this->fail(sprintf($message, "Expected error not found"));
         return;
     }
     list($severity, $content, $file, $line, $globals) = $queue->extract();
     $severity = SimpleErrorQueue::getSeverityAsString($severity);
     if (!$expected) {
         return $this->pass("Captured a PHP error of [{$content}] severity [{$severity}] in [{$file}] line [{$line}] -> %s");
     }
     $expected = $this->_coerceToExpectation($expected);
     return $this->assert($expected, $content, "Expected PHP error [{$content}] severity [{$severity}] in [{$file}] line [{$line}] -> %s");
 }
コード例 #9
0
ファイル: errors.php プロジェクト: kapai69/fl-ru-damp
/**
 *    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
 */
function SimpleTestErrorHandler($severity, $message, $filename = null, $line = null, $super_globals = null, $mask = null)
{
    $severity = $severity & error_reporting();
    if ($severity) {
        restore_error_handler();
        if (ini_get('log_errors')) {
            $label = SimpleErrorQueue::getSeverityAsString($severity);
            error_log("{$label}: {$message} in {$filename} on line {$line}");
        }
        $context =& SimpleTest::getContext();
        $queue =& $context->get('SimpleErrorQueue');
        $queue->add($severity, $message, $filename, $line);
        set_error_handler('SimpleTestErrorHandler');
    }
    return true;
}
コード例 #10
0
ファイル: errors.php プロジェクト: BackupTheBerlios/limb-svn
 /**
  *    Error handler that simply stashes any
  *    errors into the global error 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.
  *    @static
  *    @access public
  */
 function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) {
     restore_error_handler();
     if ($severity = $severity & error_reporting()) {
         $queue = &SimpleErrorQueue::instance();
         $queue->add($severity, $message, $filename, $line, $super_globals);
     }
     set_error_handler('simpleTestErrorHandler');
 }
コード例 #11
0
ファイル: errors.php プロジェクト: kitware/cdash
/**
 *    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)
{
    $severity = $severity & error_reporting();
    if ($severity) {
        restore_error_handler();
        if (IsNotCausedBySimpleTest($message) && IsNotTimeZoneNag($message)) {
            if (ini_get('log_errors')) {
                $label = SimpleErrorQueue::getSeverityAsString($severity);
                if (openlog('cdash', LOG_PID, LOG_USER)) {
                    syslog(LOG_ERR, "{$label}: {$message} in {$filename} on line {$line}");
                    closelog();
                }
            }
            $queue = SimpleTest::getContext()->get('SimpleErrorQueue');
            $queue->add($severity, $message, $filename, $line);
        }
        set_error_handler('SimpleTestErrorHandler');
    }
    return true;
}
コード例 #12
0
 function testExpectationMissTriggersError()
 {
     $test = new MockSimpleTestCase();
     $test->expectOnce('assert', array(new MockSimpleExpectation(), 'B', 'a message'));
     $test->setReturnValue('assert', false);
     $test->expectOnce('error');
     $queue = new SimpleErrorQueue();
     $queue->setTestCase($test);
     $queue->expectError(new MockSimpleExpectation(), 'a message');
     $queue->add(1024, 'B', 'b.php', 100);
 }
コード例 #13
0
ファイル: errors.php プロジェクト: guicara/simpletest
/**
 * 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)
{
    $severity = $severity & error_reporting();
    if ($severity) {
        restore_error_handler();
        // disabled filtering of errors caused by SimpleTest itself. too many things hidden for debugging. -- jakoch
        if (IsNotTimeZoneNag($message)) {
            if (ini_get('log_errors')) {
                $label = SimpleErrorQueue::getSeverityAsString($severity);
                error_log("{$label}: {$message} in {$filename} on line {$line}");
            }
            $queue = SimpleTest::getContext()->get('SimpleErrorQueue');
            $queue->add($severity, $message, $filename, $line);
        }
        set_error_handler('SimpleTestErrorHandler');
    }
    return true;
}