Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4 from scoates/master

backtrace and returns
  • Loading branch information...
commit c2a8ac0c1cf0133364b479c90c004ef64af4bff9 2 parents 0ccfb13 + 3a7b086
@funkatron authored
Showing with 35 additions and 2 deletions.
  1. +35 −2 FUnit.php
View
37 FUnit.php
@@ -97,7 +97,22 @@ public static function error_handler($num, $msg, $file, $line, $vars) {
$type = $types[$num];
- $edata = compact('datetime', 'num', 'type', 'msg', 'file', 'line');
+ $backtrace = array();
+ foreach (debug_backtrace() as $bt) {
+ if (isset($bt['function']) && __FUNCTION__ == $bt['function'] && isset($bt['class']) && __CLASS__ == $bt['class']) {
+ continue; // don't bother backtracing
+ }
+ $trace = $bt['file'] . '#' . $bt['line'];
+ if (isset($bt['class']) && isset($bt['function'])) {
+ $trace .= " {$bt['class']}::{$bt['function']}(...)";
+ } elseif (isset($bt['function'])) {
+ $trace .= " {$bt['function']}(...)";
+ }
+ $backtrace[] = $trace;
+
+ }
+
+ $edata = compact('datetime', 'num', 'type', 'msg', 'file', 'line', 'backtrace');
fu::add_error_data($edata);
}
@@ -222,7 +237,17 @@ protected static function report_text() {
}
if (count($tdata['errors']) > 0) {
foreach ($tdata['errors'] as $error) {
- fu::out( " * " . static::color(strtoupper($error['type']) . ": {$error['msg']} in {$error['file']}#{$error['line']}", 'RED') );
+ if (static::$DEBUG) {
+ $sep = "\n -> ";
+ $bt = $sep . implode($sep, $error['backtrace']);
+ } else {
+ $bt = "{$error['file']}#{$error['line']}{$bt}";
+ }
+ fu::out(
+ ' * ' . static::color(
+ strtoupper($error['type']) . ": {$error['msg']} in {$bt}",
+ 'RED')
+ );
}
}
@@ -544,6 +569,7 @@ public static function equal($a, $b, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($a, true) . ' and ' . var_export($b, true) . ' to be loosely equal');
}
+ return $rs;
}
/**
@@ -559,6 +585,7 @@ public static function not_equal($a, $b, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($a, true) . ' and ' . var_export($b, true) . ' to be unequal');
}
+ return $rs;
}
/**
@@ -574,6 +601,7 @@ public static function strict_equal($a, $b, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($a, true) . ' and ' . var_export($b, true) . ' to be strictly equal');
}
+ return $rs;
}
/**
@@ -589,6 +617,7 @@ public static function not_strict_equal($a, $b, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($a, true) . ' and ' . var_export($b, true) . ' to be strictly unequal');
}
+ return $rs;
}
/**
@@ -602,6 +631,7 @@ public static function ok($a, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($a, true) . ' to be truthy');
}
+ return $rs;
}
/**
@@ -624,6 +654,7 @@ public static function has($needle, $haystack, $msg = null) {
if (!$rs) {
static::debug_out('Expected: ' . var_export($haystack, true) . ' to contain ' . var_export($needle, true));
}
+ return $rs;
}
/**
* Force a failed assertion
@@ -632,6 +663,7 @@ public static function has($needle, $haystack, $msg = null) {
*/
public static function fail($msg = null, $expected = false) {
static::add_assertion_result(__FUNCTION__, array(), false, $msg, $expected);
+ return false;
}
/**
@@ -642,6 +674,7 @@ public static function fail($msg = null, $expected = false) {
*/
public static function expect_fail($msg = null) {
return static::fail($msg, true);
+ return false;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.