1 | <?php |
||
19 | abstract class AbstractBaseReporter implements ReporterInterface |
||
20 | { |
||
21 | use HasEventEmitterTrait; |
||
22 | |||
23 | /** |
||
24 | * @var \Peridot\Configuration |
||
25 | */ |
||
26 | protected $configuration; |
||
27 | |||
28 | /** |
||
29 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
30 | */ |
||
31 | protected $output; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $errors = []; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $passing = 0; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $pending = 0; |
||
47 | |||
48 | /** |
||
49 | * @var double|integer |
||
50 | */ |
||
51 | protected $time; |
||
52 | |||
53 | /** |
||
54 | * Maps color names to left and right color sequences. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $colors = array( |
||
59 | 'white' => ['left' => "\033[37m", 'right' => "\033[39m"], |
||
60 | 'success' => ['left' => "\033[32m", 'right' => "\033[39m"], |
||
61 | 'error' => ['left' => "\033[31m", 'right' => "\033[39m"], |
||
62 | 'warning' => ['left' => "\033[33m", 'right' => "\033[39m"], |
||
63 | 'muted' => ['left' => "\033[90m", 'right' => "\033[0m"], |
||
64 | 'pending' => ['left' => "\033[36m", 'right' => "\033[39m"], |
||
65 | ); |
||
66 | |||
67 | /** |
||
68 | * Maps symbol names to symbols |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $symbols = array( |
||
73 | 'check' => '✓' |
||
74 | ); |
||
75 | |||
76 | /** |
||
77 | * @param Configuration $configuration |
||
78 | * @param OutputInterface $output |
||
79 | * @param EventEmitterInterface $eventEmitter |
||
80 | */ |
||
81 | public function __construct( |
||
96 | |||
97 | /** |
||
98 | * Given a color name, colorize the provided text in that |
||
99 | * color |
||
100 | * |
||
101 | * @param $key |
||
102 | * @param $text |
||
103 | * @return string |
||
104 | */ |
||
105 | public function color($key, $text) |
||
118 | |||
119 | /** |
||
120 | * Fetch a symbol by name |
||
121 | * |
||
122 | * @param $name |
||
123 | * @return string |
||
124 | */ |
||
125 | public function symbol($name) |
||
129 | |||
130 | /** |
||
131 | * Return the OutputInterface associated with the Reporter |
||
132 | * |
||
133 | * @return \Symfony\Component\Console\Output\OutputInterface |
||
134 | */ |
||
135 | public function getOutput() |
||
139 | |||
140 | /** |
||
141 | * Return the Configuration associated with the Reporter |
||
142 | * |
||
143 | * @return \Peridot\Configuration |
||
144 | */ |
||
145 | public function getConfiguration() |
||
149 | |||
150 | /** |
||
151 | * Set the run time to report. |
||
152 | * |
||
153 | * @param float $time |
||
154 | */ |
||
155 | public function setTime($time) |
||
159 | |||
160 | /** |
||
161 | * Get the run time to report. |
||
162 | * |
||
163 | * @return float |
||
164 | */ |
||
165 | public function getTime() |
||
169 | |||
170 | /** |
||
171 | * Output result footer |
||
172 | */ |
||
173 | public function footer() |
||
191 | |||
192 | /** |
||
193 | * Output result warnings |
||
194 | * |
||
195 | * @param TestResult $result |
||
196 | */ |
||
197 | public function warnings(TestResult $result) |
||
203 | |||
204 | /** |
||
205 | * Output a test failure. |
||
206 | * |
||
207 | * @param int $errorNumber |
||
208 | * @param TestInterface $test |
||
209 | * @param $exception - an exception like interface with ->getMessage(), ->getTrace() |
||
210 | */ |
||
211 | protected function outputError($errorNumber, TestInterface $test, $exception) |
||
223 | |||
224 | /** |
||
225 | * Output a stack trace. |
||
226 | * |
||
227 | * @param array $trace |
||
228 | */ |
||
229 | protected function outputTrace(array $trace) |
||
245 | |||
246 | /** |
||
247 | * Determine if colorized output is supported by the reporters output. |
||
248 | * Taken from Symfony's console output with some slight modifications |
||
249 | * to use the reporter's output stream |
||
250 | * |
||
251 | * @return bool |
||
252 | */ |
||
253 | protected function hasColorSupport() |
||
261 | |||
262 | /** |
||
263 | * Register reporter symbols, additionally checking OS compatibility. |
||
264 | */ |
||
265 | protected function registerSymbols() |
||
272 | |||
273 | /** |
||
274 | * Return true if reporter is being used on windows |
||
275 | * |
||
276 | * @return bool |
||
277 | */ |
||
278 | protected function isOnWindows() |
||
282 | |||
283 | /** |
||
284 | * Register events tracking state relevant to all reporters. |
||
285 | */ |
||
286 | private function registerEvents() |
||
302 | |||
303 | /** |
||
304 | * Determine if the terminal has ansicon support |
||
305 | * |
||
306 | * @return bool |
||
307 | */ |
||
308 | private function hasAnsiSupport() |
||
312 | |||
313 | /** |
||
314 | * Determine if reporter is reporting to a tty terminal. |
||
315 | * |
||
316 | * @return bool |
||
317 | */ |
||
318 | private function hasTty() |
||
330 | |||
331 | /** |
||
332 | * See if stream output is a tty terminal. |
||
333 | * |
||
334 | * @return bool |
||
335 | */ |
||
336 | private function isTtyTerminal(StreamOutput $output) |
||
344 | |||
345 | /** |
||
346 | * Initialize reporter. Setup and listen for events |
||
347 | * |
||
348 | * @return void |
||
349 | */ |
||
350 | abstract public function init(); |
||
351 | |||
352 | private function renderTraceEntry($index, array $entry, $function) |
||
362 | } |
||
363 |