lithium\test\Report::stats PHP Method

stats() public method

Return statistics from the test runs.
public stats ( ) : array
return array
    public function stats()
    {
        $results = (array) $this->results['group'];
        $defaults = array('asserts' => 0, 'passes' => array(), 'fails' => array(), 'exceptions' => array(), 'errors' => array(), 'skips' => array());
        $stats = array_reduce($results, function ($stats, $result) use($defaults) {
            $stats = (array) $stats + $defaults;
            $result = empty($result[0]) ? array($result) : $result;
            foreach ($result as $response) {
                if (empty($response['result'])) {
                    continue;
                }
                $result = $response['result'];
                if (in_array($result, array('fail', 'exception'))) {
                    $response = array_merge(array('class' => 'unknown', 'method' => 'unknown'), $response);
                    $stats['errors'][] = $response;
                }
                unset($response['file'], $response['result']);
                if (in_array($result, array('pass', 'fail'))) {
                    $stats['asserts']++;
                }
                if (in_array($result, array('pass', 'fail', 'exception', 'skip'))) {
                    $stats[Inflector::pluralize($result)][] = $response;
                }
            }
            return $stats;
        });
        $stats = (array) $stats + $defaults;
        $count = array_map(function ($value) {
            return is_array($value) ? count($value) : $value;
        }, $stats);
        $success = $count['passes'] === $count['asserts'] && $count['errors'] === 0;
        return compact('stats', 'count', 'success');
    }

Usage Example

Example #1
0
 public function testRender()
 {
     $report = new Report(array('title' => '\\lithium\\tests\\mocks\\test\\MockUnitTest', 'group' => new Group(array('data' => array('\\lithium\\tests\\mocks\\test\\MockUnitTest'))), 'format' => 'txt'));
     $report->run();
     $result = $report->render('result', $report->stats());
     $this->assertPattern('#2.*2.*passes.*0.*fails.*0.*exceptions#s', $result);
 }
All Usage Examples Of lithium\test\Report::stats