Property | Type | Description | |
---|---|---|---|
$DEBUG | debug mode | ||
$DEBUG_COLOR | |||
$INFO_COLOR | |||
$SILENCE | boolean | if true, nothing will be output but the report | |
$all_run_tests | $tests['name'] => array( 'run'=>false, 'skipped'=>false, 'pass'=>false, 'test'=>null, 'assertions'=>array('func_name'=>'foo', 'func_args'=array('a','b'), 'result'=>$result, 'msg'=>'blahblah'), 'timing' => array('setup'=>ts, 'run'=>ts, 'teardown'=>ts, 'total'=ts), | ||
$current_suite_name | |||
$disable_reporting | boolean | if true, will not output a report | |
$disable_run | boolean | this is used by the test runner utility to suppress FUnit::run() calls in required files | |
$errors | |||
$fixtures | |||
$setup_func | |||
$suites | $suites['name'] => \FUnit\TestSuite | ||
$teardown_func |
Property | Type | Description | |
---|---|---|---|
$TERM_COLORS |
Method | Description | |
---|---|---|
__callStatic ( string $name, array $arguments ) : [type] | We use this magic method to map various assertion calls to assert_{$name}() This is so we can break out the call to add_assertion_result() and test the assertion methods properly | |
after ( Closure $after ) | register a function to run after the current suite's tests | |
assert_all_ok ( array | Traversable $a, callable $callback, string $msg = null ) | Iterate over all the items in $a and pass each to $callback. If the callback returns true for all, it passes -- otherwise it fails | |
assert_equal ( mixed $a, mixed $b, string $msg = null ) | assert that $a is equal to $b. Uses == for comparison | |
assert_expect_fail ( string $msg = null ) | Fail an assertion in an expected way | |
assert_fail ( string $msg = null, $expected = false ) | Force a failed assertion | |
assert_has ( string $needle, array | object $haystack, string $msg = null ) | assert that $haystack has a key or property named $needle. If $haystack is neither, returns false | |
assert_not_equal ( mixed $a, mixed $b, string $msg = null ) | assert that $a is not equal to $b. Uses != for comparison | |
assert_not_has ( string $needle, array | object $haystack, string $msg = null ) | assert that $haystack does not have a key or property named $needle. If $haystack is neither an array or object, returns false | |
assert_not_ok ( mixed $a, string $msg = null ) | assert that $a is falsy. Casts $a to boolean for result | |
assert_not_strict_equal ( mixed $a, mixed $b, string $msg = null ) | assert that $a is strictly not equal to $b. Uses !== for comparison | |
assert_ok ( mixed $a, string $msg = null ) | assert that $a is truthy. Casts $a to boolean for result | |
assert_pass ( string $msg = null ) | Force a successful assertion | |
assert_strict_equal ( mixed $a, mixed $b, string $msg = null ) | assert that $a is strictly equal to $b. Uses === for comparison | |
assert_throws ( callable $callback, array $params, string $exception = null, string $msg = null ) : boolean | assert that $callback throws an exception of type $exception | |
assertion_stats ( array $tests, string $test_name = null ) : array | Retrieves stats about assertions run. returns an array with the keys 'total', 'pass', 'fail', 'expected_fail' | |
before ( Closure $before ) | register a function to run before the current suite's tests | |
debug_out ( $str ) | ||
error_handler ( $num, $msg, $file, $line, $vars ) | custom error handler to catch errors triggered while running tests. this is registered at the start of FUnit::run() and deregistered at stop | |
exception_handler ( Exception $e ) : array | custom exception handler, massaging the format into the same we use for Errors | |
exit_code ( ) : integer | Retrieve the exit code. It scans all suites for their exit codes, and if AND of them are 1, returns 1. Else 0. | |
fixture ( string $key, mixed $val = null ) : mixed | helper to deal with scoping fixtures. To store a fixture: FUnit::fixture('foo', 'bar'); to retrieve a fixture: FUnit::fixture('foo'); | |
get_current_suite ( ) : FUnit\TestSuite | null | get the current suite. If none current, return null | |
get_suite ( string $name ) : FUnit\TestSuite | get an FUnit\TestSuite by name | |
info_out ( $str ) | ||
parse_backtrace ( array $bt_raw ) : array | this generates an array of formatted strings to represent the backtrace | |
report ( string $format = 'text', array $tests_data = [] ) | Output a report | |
report_all_tests ( string $format ) | output a report for all tests than have been run from all suites | |
report_out ( $str ) | ||
reset_fixtures ( ) | removes all fixtures. This won't magically close connections or files, tho | |
run ( boolean $report = true, string $filter = null, $report_format = null ) | Run the registered tests, and output a report | |
run_tests ( string $filter = null ) | Normally you would not call this method directly | |
set_debug ( boolean $state ) | if true, debugging info will be output. | |
set_disable_reporting ( boolean $state ) | Passing true will disable the reporting output | |
set_disable_run ( boolean $state ) | Passing true will disable the FUnit::run() method. This is used by the test runner utility to avoid calls to run tests within scripts | |
set_silence ( boolean $state ) | if $SILENCE is true, only the report will be output -- no progress etc. | |
setup ( Closure $setup ) | register a function to run at the start of each test | |
str_truncate ( $str_val, integer $maxlen ) : string | truncates a string. If no second param is passed, no change is made | |
suite ( string $name = self::DEFAULT_SUITE_NAME ) | initialize a new test suite. adds a suite to \FUnit::$suites and sets \FUnit::$current_suite_name to the new suite's name | |
teardown ( Closure $teardown ) | register a function to run at the end of each test | |
test ( string $name, Closure $test ) | add a test to be run | |
test_stats ( array $tests ) : array | Retrieves stats about tests run. returns an array with the keys 'total', 'pass', 'run' | |
val_to_string ( mixed $val, integer $maxlen = 50 ) : string | converts all known PHP types into a string representation. Generally would be less verbose with objects and arrays than FUnit::var_export() because it uses json_encode() | |
var_export ( mixed $val, integer $maxlen = 50 ) : string | uses var_export to get string representation of a value. This differs from the standard var_export by removing newlines and allowing optional truncation |
Method | Description | |
---|---|---|
add_assertion_result ( TestSuite $suite, string $func_name, array $func_args, mixed $result, $file, $line, $fail_info, string $msg = null, boolean $expected_fail = false ) | add the result of an assertion | |
add_error_data ( array $edata ) | adds error data to the main $errors var property and the current test's error array | |
add_suite ( string $name = self::DEFAULT_SUITE_NAME ) | add a test suite | |
add_test ( string $name, Closure $test ) | add a test to be executed | |
check_current_suite ( ) | check if a current suite exists. If not, create a new one and assign its name to static::$current_suite_name | |
color ( $txt, string $color = 'DEFAULT' ) | Format a line for printing. Detects if the script is being run from the command line or from a browser; also detects TTY for color (so pipes work). | |
out ( $str ) | ||
report_text ( array $tests ) | Output a report as text | |
report_xunit ( array $tests ) | Output a report as xunit format (Jenkins-compatible) | |
run_test ( string $name ) | Normally you would not call this method directly |
public static __callStatic ( string $name, array $arguments ) : [type] | ||
$name | string | the assertion short name |
$arguments | array | arguments to pass to "\FUnit::{$assert_name}()" |
return | [type] |
protected static add_assertion_result ( TestSuite $suite, string $func_name, array $func_args, mixed $result, $file, $line, $fail_info, string $msg = null, boolean $expected_fail = false ) | ||
$suite | FUnit\TestSuite | the suite to add the result to |
$func_name | string | the name of the assertion function |
$func_args | array | the arguments for the assertion. Really just the $a (actual) and $b (expected) |
$result | mixed | this is expected to be truthy or falsy, and is converted into FUnit::PASS or FUnit::FAIL |
$msg | string | optional message describing the assertion |
$expected_fail | boolean | optional expectation of the assertion to fail |
protected static add_error_data ( array $edata ) | ||
$edata | array | ['datetime', 'num', 'type', 'msg', 'file', 'line'] |
public static assert_all_ok ( array | Traversable $a, callable $callback, string $msg = null ) | ||
$a | array | Traversable | an array or Traversable (iterable) object |
$callback | callable | [description] |
$msg | string | optional description of assertion |
public static assert_expect_fail ( string $msg = null ) | ||
$msg | string | optional description of assertion |
public static assert_fail ( string $msg = null, $expected = false ) | ||
$msg | string | optional description of assertion |
public static assert_not_ok ( mixed $a, string $msg = null ) | ||
$a | mixed | the actual value |
$msg | string | optional description of assertion |
public static assert_pass ( string $msg = null ) | ||
$msg | string | optional description of assertion |
public static assert_throws ( callable $callback, array $params, string $exception = null, string $msg = null ) : boolean | ||
$callback | callable | Callback that should throw an exception |
$params | array | Callback that should throw an exception |
$exception | string | The exception class that should be thrown |
$msg | string | |
return | boolean |
protected static check_current_suite ( ) |
public static error_handler ( $num, $msg, $file, $line, $vars ) |
public static exception_handler ( Exception $e ) : array | ||
$e | Exception | |
return | array | ['datetime', 'num', 'type', 'msg', 'file', 'line'] |
public static get_current_suite ( ) : FUnit\TestSuite | null | ||
return | FUnit\TestSuite | null |
public static parse_backtrace ( array $bt_raw ) : array | ||
$bt_raw | array | the raw backtrace array |
return | array | an array of strings |
public static report_all_tests ( string $format ) | ||
$format | string | 'text' (default) or 'xunit'. |
protected static report_text ( array $tests ) | ||
$tests | array |
protected static report_xunit ( array $tests ) | ||
$tests | array |
public static reset_fixtures ( ) |
public static set_disable_reporting ( boolean $state ) | ||
$state | boolean |
public static set_disable_run ( boolean $state ) | ||
$state | boolean |
public static set_silence ( boolean $state ) | ||
$state | boolean |
public static str_truncate ( $str_val, integer $maxlen ) : string | ||
$maxlen | integer | if > 0, truncate the string rep (default 0) |
return | string |
public static test_stats ( array $tests ) : array | ||
$tests | array | a set of test results |
return | array | has keys 'total', 'pass', 'run', 'error' |
public static bool $SILENCE | ||
return | boolean |
public static $all_run_tests |
public static bool $disable_reporting | ||
return | boolean |
public static bool $disable_run | ||
return | boolean |