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