|
16 | 16 | */ |
17 | 17 | class lime_test |
18 | 18 | { |
19 | | - public const EPSILON = 0.0000000001; |
| 19 | + const EPSILON = 0.0000000001; |
20 | 20 |
|
21 | 21 | protected $test_nb = 0; |
22 | 22 | protected $output = null; |
23 | 23 | protected $results = array(); |
24 | 24 | protected $options = array(); |
25 | 25 |
|
26 | | - protected static $all_results = array(); |
27 | | - |
28 | | - private const STATE_PASS = 0; |
29 | | - private const STATE_FAIL = 1; |
30 | | - |
31 | | - private static $instanceCount = 0; |
32 | | - private static $finalState = self::STATE_PASS; |
| 26 | + static protected $all_results = array(); |
33 | 27 |
|
34 | 28 | public function __construct($plan = null, $options = array()) |
35 | 29 | { |
36 | | - ++self::$instanceCount; |
37 | | - |
38 | 30 | // for BC |
39 | 31 | if (!is_array($options)) |
40 | 32 | { |
@@ -137,87 +129,32 @@ static public function to_xml($results = null) |
137 | 129 | } |
138 | 130 |
|
139 | 131 | public function __destruct() |
140 | | - { |
141 | | - $testSuiteState = $this->determineAndPrintStateOfTestSuite(); |
142 | | - |
143 | | - flush(); |
144 | | - |
145 | | - $this->keepTheWorstState($testSuiteState); |
146 | | - |
147 | | - $this->finalizeLastInstanceDestructorWithProcessExit(); |
148 | | - } |
149 | | - |
150 | | - private function determineAndPrintStateOfTestSuite(): int |
151 | | - { |
152 | | - $planState = $this->determineAndPrintStateOfPlan(); |
153 | | - $failed = count($this->results['stats']['failed']); |
154 | | - |
155 | | - if ($failed) { |
156 | | - $passed = count($this->results['stats']['passed']); |
157 | | - |
158 | | - $this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed)); |
159 | | - |
160 | | - return self::STATE_FAIL; |
161 | | - } |
162 | | - |
163 | | - if (self::STATE_FAIL === $planState) { |
164 | | - return self::STATE_FAIL; |
165 | | - } |
166 | | - |
167 | | - $this->output->green_bar("# Looks like everything went fine."); |
168 | | - |
169 | | - return self::STATE_PASS; |
170 | | - } |
171 | | - |
172 | | - private function determineAndPrintStateOfPlan(): int |
173 | 132 | { |
174 | 133 | $plan = $this->results['stats']['plan']; |
| 134 | + $passed = count($this->results['stats']['passed']); |
| 135 | + $failed = count($this->results['stats']['failed']); |
175 | 136 | $total = $this->results['stats']['total']; |
| 137 | + is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); |
176 | 138 |
|
177 | | - if (null === $plan) { |
178 | | - $plan = $total; |
179 | | - |
180 | | - $this->output->echoln(sprintf("1..%d", $plan)); |
181 | | - } |
182 | | - |
183 | | - if ($total > $plan) { |
| 139 | + if ($total > $plan) |
| 140 | + { |
184 | 141 | $this->output->red_bar(sprintf("# Looks like you planned %d tests but ran %d extra.", $plan, $total - $plan)); |
185 | | - } elseif ($total < $plan) { |
| 142 | + } |
| 143 | + elseif ($total < $plan) |
| 144 | + { |
186 | 145 | $this->output->red_bar(sprintf("# Looks like you planned %d tests but only ran %d.", $plan, $total)); |
187 | 146 | } |
188 | 147 |
|
189 | | - return $total === $plan ? self::STATE_PASS : self::STATE_FAIL; |
190 | | - } |
191 | | - |
192 | | - private function keepTheWorstState(int $state): void |
193 | | - { |
194 | | - if ($this->stateIsTheWorst($state)) { |
195 | | - self::$finalState = $state; |
| 148 | + if ($failed) |
| 149 | + { |
| 150 | + $this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed)); |
196 | 151 | } |
197 | | - } |
198 | | - |
199 | | - private function stateIsTheWorst(int $state): bool |
200 | | - { |
201 | | - return self::$finalState < $state; |
202 | | - } |
203 | | - |
204 | | - private function finalizeLastInstanceDestructorWithProcessExit(): void |
205 | | - { |
206 | | - --self::$instanceCount; |
207 | | - |
208 | | - if (0 === self::$instanceCount) { |
209 | | - exit($this->determineExitCodeFromState(self::$finalState)); |
| 152 | + else if ($total == $plan) |
| 153 | + { |
| 154 | + $this->output->green_bar("# Looks like everything went fine."); |
210 | 155 | } |
211 | | - } |
212 | 156 |
|
213 | | - private function determineExitCodeFromState(int $state): int |
214 | | - { |
215 | | - switch ($state) { |
216 | | - case self::STATE_PASS: |
217 | | - return 0; |
218 | | - default: |
219 | | - return 1; |
220 | | - } |
| 157 | + flush(); |
221 | 158 | } |
222 | 159 |
|
223 | 160 | /** |
@@ -1032,7 +969,7 @@ function lime_shutdown() |
1032 | 969 | $delta = 0; |
1033 | 970 | if ($return > 0) |
1034 | 971 | { |
1035 | | - $stats['status'] = $file_stats['failed'] ? 'not ok' : ($file_stats['errors'] ? 'errors' : 'dubious'); |
| 972 | + $stats['status'] = $file_stats['errors'] ? 'errors' : 'dubious'; |
1036 | 973 | $stats['status_code'] = $return; |
1037 | 974 | } |
1038 | 975 | else |
|
0 commit comments