Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Statistics / TotalStatistics.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Output\Statistics;
12
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;
18
19 /**
20  * Collects and provided exercise statistics.
21  *
22  * @author Konstantin Kudryashov <ever.zet@gmail.com>
23  */
24 final class TotalStatistics implements Statistics
25 {
26     /**
27      * @var Timer
28      */
29     private $timer;
30     /**
31      * @var Memory
32      */
33     private $memory;
34     /**
35      * @var array
36      */
37     private $scenarioCounters = array();
38     /**
39      * @var array
40      */
41     private $stepCounters = array();
42     /**
43      * @var ScenarioStat[]
44      */
45     private $failedScenarioStats = array();
46     /**
47      * @var ScenarioStat[]
48      */
49     private $skippedScenarioStats = array();
50     /**
51      * @var StepStat[]
52      */
53     private $failedStepStats = array();
54     /**
55      * @var StepStat[]
56      */
57     private $pendingStepStats = array();
58     /**
59      * @var HookStat[]
60      */
61     private $failedHookStats = array();
62
63     /**
64      * Initializes statistics.
65      */
66     public function __construct()
67     {
68         $this->resetAllCounters();
69
70         $this->timer = new Timer();
71         $this->memory = new Memory();
72     }
73
74     public function resetAllCounters()
75     {
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
82         );
83     }
84
85     /**
86      * Starts timer.
87      */
88     public function startTimer()
89     {
90         $this->timer->start();
91     }
92
93     /**
94      * Stops timer.
95      */
96     public function stopTimer()
97     {
98         $this->timer->stop();
99     }
100
101     /**
102      * Returns timer object.
103      *
104      * @return Timer
105      */
106     public function getTimer()
107     {
108         return $this->timer;
109     }
110
111     /**
112      * Returns memory usage object.
113      *
114      * @return Memory
115      */
116     public function getMemory()
117     {
118         return $this->memory;
119     }
120
121     /**
122      * Registers scenario stat.
123      *
124      * @param ScenarioStat $stat
125      */
126     public function registerScenarioStat(ScenarioStat $stat)
127     {
128         if (TestResults::NO_TESTS === $stat->getResultCode()) {
129             return;
130         }
131
132         $this->scenarioCounters[$stat->getResultCode()]++;
133
134         if (TestResult::FAILED === $stat->getResultCode()) {
135             $this->failedScenarioStats[] = $stat;
136         }
137
138         if (TestResult::SKIPPED === $stat->getResultCode()) {
139             $this->skippedScenarioStats[] = $stat;
140         }
141     }
142
143     /**
144      * Registers step stat.
145      *
146      * @param StepStat $stat
147      */
148     public function registerStepStat(StepStat $stat)
149     {
150         $this->stepCounters[$stat->getResultCode()]++;
151
152         if (TestResult::FAILED === $stat->getResultCode()) {
153             $this->failedStepStats[] = $stat;
154         }
155
156         if (TestResult::PENDING === $stat->getResultCode()) {
157             $this->pendingStepStats[] = $stat;
158         }
159     }
160
161     /**
162      * Registers hook stat.
163      *
164      * @param HookStat $stat
165      */
166     public function registerHookStat(HookStat $stat)
167     {
168         if ($stat->isSuccessful()) {
169             return;
170         }
171
172         $this->failedHookStats[] = $stat;
173     }
174
175     /**
176      * Returns counters for different scenario result codes.
177      *
178      * @return array[]
179      */
180     public function getScenarioStatCounts()
181     {
182         return $this->scenarioCounters;
183     }
184
185     /**
186      * Returns skipped scenario stats.
187      *
188      * @return ScenarioStat[]
189      */
190     public function getSkippedScenarios()
191     {
192         return $this->skippedScenarioStats;
193     }
194
195     /**
196      * Returns failed scenario stats.
197      *
198      * @return ScenarioStat[]
199      */
200     public function getFailedScenarios()
201     {
202         return $this->failedScenarioStats;
203     }
204
205     /**
206      * Returns counters for different step result codes.
207      *
208      * @return array[]
209      */
210     public function getStepStatCounts()
211     {
212         return $this->stepCounters;
213     }
214
215     /**
216      * Returns failed step stats.
217      *
218      * @return StepStat[]
219      */
220     public function getFailedSteps()
221     {
222         return $this->failedStepStats;
223     }
224
225     /**
226      * Returns pending step stats.
227      *
228      * @return StepStat[]
229      */
230     public function getPendingSteps()
231     {
232         return $this->pendingStepStats;
233     }
234
235     /**
236      * Returns failed hook stats.
237      *
238      * @return HookStat[]
239      */
240     public function getFailedHookStats()
241     {
242         return $this->failedHookStats;
243     }
244 }