Skip to content

Commit 41fea0e

Browse files
committed
allow ass. results to be recored on passed suite
1 parent c52eae2 commit 41fea0e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/FUnit.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ public static function get_current_suite()
577577
*
578578
* Normally you would not call this method directly
579579
*
580+
* @param \FUnit\TestSuite $suite the suite to add the result to
580581
* @param string $func_name the name of the assertion function
581582
* @param array $func_args the arguments for the assertion. Really just the $a (actual) and $b (expected)
582583
* @param mixed $result this is expected to be truthy or falsy, and is converted into FUnit::PASS or FUnit::FAIL
@@ -588,9 +589,8 @@ public static function get_current_suite()
588589
* @see FUnit::strict_equal()
589590
* @see FUnit::not_strict_equal()
590591
*/
591-
protected static function add_assertion_result($func_name, $func_args, $result, $file, $line, $fail_info, $msg = null, $expected_fail = false)
592+
protected static function add_assertion_result(\FUnit\TestSuite $suite, $func_name, $func_args, $result, $file, $line, $fail_info, $msg = null, $expected_fail = false)
592593
{
593-
$suite = static::get_current_suite();
594594
$suite->addAssertionResult($func_name, $func_args, $result, $file, $line, $fail_info, $msg, $expected_fail);
595595
}
596596

@@ -747,6 +747,18 @@ public static function __callStatic($name, $arguments)
747747
{
748748
$assert_name = 'assert_' . $name;
749749
$call_str = "\FUnit::{$assert_name}";
750+
751+
/**
752+
* Assertions are called in the context of a suite. By default we use
753+
* the "current" suite, but we can force a different suite by passing
754+
* the suite object as the first argument. This is mainly so we can test
755+
* suites themselves.
756+
*/
757+
$suite = static::get_current_suite();
758+
if (isset($arguments[0]) && $arguments[0] instanceof \FUnit\TestSuite) {
759+
$suite = array_shift($arguments);
760+
}
761+
750762
if (method_exists('\FUnit', $assert_name)) {
751763

752764
switch ($assert_name) {
@@ -783,7 +795,7 @@ public static function __callStatic($name, $arguments)
783795
$assert_trace = array_shift($btrace);
784796
$file = $assert_trace['file'];
785797
$line = $assert_trace['line'];
786-
static::add_assertion_result($call_str, $arguments, $rs, $file, $line, $fail_info, $msg, $expected_fail);
798+
static::add_assertion_result($suite, $call_str, $arguments, $rs, $file, $line, $fail_info, $msg, $expected_fail);
787799
return $rs;
788800
}
789801
throw new \BadMethodCallException("Method {$assert_name} does not exist");

src/TestSuite.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function addErrorData($edata)
141141
*/
142142
public function addAssertionResult($func_name, $func_args, $result, $file, $line, $fail_info, $msg = null, $expected_fail = false)
143143
{
144+
\FUnit::debug_out("Adding assertion result for '{$func_name}' to suite '" . $this->getName() . "'");
144145
$result = ($result) ? \FUnit::PASS : \FUnit::FAIL;
145146
$refl_meth = new \ReflectionMethod($func_name);
146147
$args_strs = array();
@@ -178,7 +179,7 @@ public function runTest($name)
178179
return $this->tests[$name];
179180
}
180181

181-
\FUnit::info_out("Running test '{$name}...'");
182+
\FUnit::info_out("Running test '{$name}' in suite {$this->getName()}");
182183

183184
$ts_start = microtime(true);
184185

0 commit comments

Comments
 (0)