lithium\test\Report::stats()

public method

Return statistics from the test runs.

Returns

array

Source

	public function stats() {
		$results = (array) $this->results['group'];
		$defaults = [
			'asserts' => 0,
			'passes' => [],
			'fails' => [],
			'exceptions' => [],
			'errors' => [],
			'skips' => []
		];
		$stats = array_reduce($results, function($stats, $result) use ($defaults) {
			$stats = (array) $stats + $defaults;
			$result = empty($result[0]) ? [$result] : $result;
			foreach ($result as $response) {
				if (empty($response['result'])) {
					continue;
				}
				$result = $response['result'];

				if (in_array($result, ['fail', 'exception'])) {
					$response = array_merge(
						['class' => 'unknown', 'method' => 'unknown'], $response
					);
					$stats['errors'][] = $response;
				}
				unset($response['file'], $response['result']);

				if (in_array($result, ['pass', 'fail'])) {
					$stats['asserts']++;
				}
				if (in_array($result, ['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');
	}