FUnit::assertion_stats PHP Метод

assertion_stats() публичный статический Метод

If called without passing a test name, retrieves info about all assertions. Else just for the named test
public static assertion_stats ( array $tests, string $test_name = null ) : array
$tests array a set of test results
$test_name string optional the name of the test about which to get assertion stats
Результат array has keys 'total', 'pass', 'fail', 'expected_fail'
    public static function assertion_stats(array $tests, $test_name = null)
    {
        $total = 0;
        $pass = 0;
        $fail = 0;
        $expected_fail = 0;
        $test_asserts = function ($test_name, $assertions) {
            $total = 0;
            $pass = 0;
            $fail = 0;
            $expected_fail = 0;
            foreach ($assertions as $ass) {
                if ($ass['result'] === \FUnit::PASS) {
                    $pass++;
                } elseif ($ass['result'] === \FUnit::FAIL) {
                    $fail++;
                    if ($ass['expected_fail']) {
                        $expected_fail++;
                    }
                }
                $total++;
            }
            return compact('total', 'pass', 'fail', 'expected_fail');
        };
        if ($test_name) {
            $assertions = $tests[$test_name]['assertions'];
            $rs = $test_asserts($test_name, $assertions);
            $total += $rs['total'];
            $pass += $rs['pass'];
            $fail += $rs['fail'];
            $expected_fail += $rs['expected_fail'];
        } else {
            foreach ($tests as $test_name => $tdata) {
                $assertions = $tests[$test_name]['assertions'];
                $rs = $test_asserts($test_name, $assertions);
                $total += $rs['total'];
                $pass += $rs['pass'];
                $fail += $rs['fail'];
                $expected_fail += $rs['expected_fail'];
            }
        }
        return compact('total', 'pass', 'fail', 'expected_fail');
    }

Usage Example

Пример #1
0
 /**
  * @see \FUnit::assertion_stats()
  * @return array
  */
 public function assertCounts($test_name = null)
 {
     return \FUnit::assertion_stats($this->tests, $test_name);
 }