@@ -577,6 +577,7 @@ public static function get_current_suite()
577
577
*
578
578
* Normally you would not call this method directly
579
579
*
580
+ * @param \FUnit\TestSuite $suite the suite to add the result to
580
581
* @param string $func_name the name of the assertion function
581
582
* @param array $func_args the arguments for the assertion. Really just the $a (actual) and $b (expected)
582
583
* @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()
588
589
* @see FUnit::strict_equal()
589
590
* @see FUnit::not_strict_equal()
590
591
*/
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 )
592
593
{
593
- $ suite = static ::get_current_suite ();
594
594
$ suite ->addAssertionResult ($ func_name , $ func_args , $ result , $ file , $ line , $ fail_info , $ msg , $ expected_fail );
595
595
}
596
596
@@ -747,6 +747,18 @@ public static function __callStatic($name, $arguments)
747
747
{
748
748
$ assert_name = 'assert_ ' . $ name ;
749
749
$ 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
+
750
762
if (method_exists ('\FUnit ' , $ assert_name )) {
751
763
752
764
switch ($ assert_name ) {
@@ -783,7 +795,7 @@ public static function __callStatic($name, $arguments)
783
795
$ assert_trace = array_shift ($ btrace );
784
796
$ file = $ assert_trace ['file ' ];
785
797
$ 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 );
787
799
return $ rs ;
788
800
}
789
801
throw new \BadMethodCallException ("Method {$ assert_name } does not exist " );
0 commit comments