4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Output\Statistics;
13 use Behat\Behat\Tester\Result\StepResult;
14 use Behat\Testwork\Counter\Memory;
15 use Behat\Testwork\Counter\Timer;
16 use Behat\Testwork\Tester\Result\TestResult;
17 use Behat\Testwork\Tester\Result\TestResults;
20 * Collects and provided exercise statistics.
22 * @author Konstantin Kudryashov <ever.zet@gmail.com>
24 final class TotalStatistics implements Statistics
37 private $scenarioCounters = array();
41 private $stepCounters = array();
45 private $failedScenarioStats = array();
49 private $skippedScenarioStats = array();
53 private $failedStepStats = array();
57 private $pendingStepStats = array();
61 private $failedHookStats = array();
64 * Initializes statistics.
66 public function __construct()
68 $this->resetAllCounters();
70 $this->timer = new Timer();
71 $this->memory = new Memory();
74 public function resetAllCounters()
76 $this->scenarioCounters = $this->stepCounters = array(
77 TestResult::PASSED => 0,
78 TestResult::FAILED => 0,
79 StepResult::UNDEFINED => 0,
80 TestResult::PENDING => 0,
81 TestResult::SKIPPED => 0
88 public function startTimer()
90 $this->timer->start();
96 public function stopTimer()
102 * Returns timer object.
106 public function getTimer()
112 * Returns memory usage object.
116 public function getMemory()
118 return $this->memory;
122 * Registers scenario stat.
124 * @param ScenarioStat $stat
126 public function registerScenarioStat(ScenarioStat $stat)
128 if (TestResults::NO_TESTS === $stat->getResultCode()) {
132 $this->scenarioCounters[$stat->getResultCode()]++;
134 if (TestResult::FAILED === $stat->getResultCode()) {
135 $this->failedScenarioStats[] = $stat;
138 if (TestResult::SKIPPED === $stat->getResultCode()) {
139 $this->skippedScenarioStats[] = $stat;
144 * Registers step stat.
146 * @param StepStat $stat
148 public function registerStepStat(StepStat $stat)
150 $this->stepCounters[$stat->getResultCode()]++;
152 if (TestResult::FAILED === $stat->getResultCode()) {
153 $this->failedStepStats[] = $stat;
156 if (TestResult::PENDING === $stat->getResultCode()) {
157 $this->pendingStepStats[] = $stat;
162 * Registers hook stat.
164 * @param HookStat $stat
166 public function registerHookStat(HookStat $stat)
168 if ($stat->isSuccessful()) {
172 $this->failedHookStats[] = $stat;
176 * Returns counters for different scenario result codes.
180 public function getScenarioStatCounts()
182 return $this->scenarioCounters;
186 * Returns skipped scenario stats.
188 * @return ScenarioStat[]
190 public function getSkippedScenarios()
192 return $this->skippedScenarioStats;
196 * Returns failed scenario stats.
198 * @return ScenarioStat[]
200 public function getFailedScenarios()
202 return $this->failedScenarioStats;
206 * Returns counters for different step result codes.
210 public function getStepStatCounts()
212 return $this->stepCounters;
216 * Returns failed step stats.
220 public function getFailedSteps()
222 return $this->failedStepStats;
226 * Returns pending step stats.
230 public function getPendingSteps()
232 return $this->pendingStepStats;
236 * Returns failed hook stats.
240 public function getFailedHookStats()
242 return $this->failedHookStats;