1 | <?php |
||
10 | class Configuration |
||
11 | { |
||
12 | /** |
||
13 | * @var boolean |
||
14 | */ |
||
15 | protected $colorsEnabled = true; |
||
16 | |||
17 | /** |
||
18 | * @var boolean |
||
19 | */ |
||
20 | protected $colorsEnableExplicit = false; |
||
21 | |||
22 | /** |
||
23 | * @var string|null |
||
24 | */ |
||
25 | protected $focusPattern; |
||
26 | |||
27 | /** |
||
28 | * @var string|null |
||
29 | */ |
||
30 | protected $skipPattern; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $grep = '*.spec.php'; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $reporters = ['spec']; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $path; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $configurationFile; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $dsl; |
||
56 | |||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | protected $stopOnFailure = false; |
||
61 | |||
62 | public function __construct() |
||
68 | |||
69 | /** |
||
70 | * Set the pattern used to load tests |
||
71 | * |
||
72 | * @param string $grep |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function setGrep($grep) |
||
79 | |||
80 | /** |
||
81 | * Returns the pattern used to load tests |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getGrep() |
||
89 | |||
90 | /** |
||
91 | * Set the pattern used to focus tests |
||
92 | * |
||
93 | * @param string|null $pattern |
||
94 | * @return $this |
||
95 | */ |
||
96 | public function setFocusPattern($pattern) |
||
100 | |||
101 | /** |
||
102 | * Returns the pattern used to focus tests |
||
103 | * |
||
104 | * @return string|null |
||
105 | */ |
||
106 | public function getFocusPattern() |
||
110 | |||
111 | /** |
||
112 | * Set the pattern used to skip tests |
||
113 | * |
||
114 | * @param string|null $pattern |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function setSkipPattern($pattern) |
||
121 | |||
122 | /** |
||
123 | * Returns the pattern used to skip tests |
||
124 | * |
||
125 | * @return string|null |
||
126 | */ |
||
127 | public function getSkipPattern() |
||
131 | |||
132 | /** |
||
133 | * Set the name of the reporter to use |
||
134 | * |
||
135 | * @param string $reporter |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function setReporter($reporter) |
||
142 | |||
143 | /** |
||
144 | * Return the name of the reporter configured for use |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getReporter() |
||
152 | |||
153 | /** |
||
154 | * Set the names of the reporters to use |
||
155 | * |
||
156 | * @param array $reporters |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function setReporters(array $reporters) |
||
160 | { |
||
161 | if (empty($reporters)) { |
||
162 | throw new \InvalidArgumentException('Reporters cannot be empty.'); |
||
163 | } |
||
164 | |||
165 | return $this->writeReporters($reporters); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Return the names of the reporters configured for use |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | public function getReporters() |
||
174 | { |
||
175 | return $this->reporters; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Set the path to load tests from |
||
180 | * |
||
181 | * @param string $path |
||
182 | * @return $this |
||
183 | */ |
||
184 | public function setPath($path) |
||
185 | { |
||
186 | return $this->write('path', $path); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Return the path being searched for tests |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | public function getPath() |
||
195 | { |
||
196 | return $this->path; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Disable output colors |
||
201 | * |
||
202 | * @return $this |
||
203 | */ |
||
204 | public function disableColors() |
||
212 | |||
213 | /** |
||
214 | * Force output colors even without TTY support. |
||
215 | * |
||
216 | * @return $this |
||
217 | */ |
||
218 | public function enableColorsExplicit() |
||
224 | |||
225 | /** |
||
226 | * Check if output colors are disabled |
||
227 | * |
||
228 | * @return boolean |
||
229 | */ |
||
230 | public function areColorsEnabled() |
||
234 | |||
235 | /** |
||
236 | * Check if output colors are explicitly enabled. |
||
237 | * |
||
238 | * @return boolean |
||
239 | */ |
||
240 | public function areColorsEnabledExplicit() |
||
244 | |||
245 | /** |
||
246 | * Stop the suite runner when a failure occurs |
||
247 | * |
||
248 | * @return $this |
||
249 | */ |
||
250 | public function stopOnFailure() |
||
254 | |||
255 | /** |
||
256 | * Check if the suite runner should stop on failure |
||
257 | * |
||
258 | * @return bool |
||
259 | */ |
||
260 | public function shouldStopOnFailure() |
||
264 | |||
265 | /** |
||
266 | * Set the path to a Peridot configuration file |
||
267 | * |
||
268 | * @param string $configurationFile |
||
269 | * @return $this |
||
270 | */ |
||
271 | public function setConfigurationFile($configurationFile) |
||
284 | |||
285 | /** |
||
286 | * Return the path to the Peridot configuration file. Returns a relative |
||
287 | * path if it exists, otherwise return the provided value |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getConfigurationFile() |
||
295 | |||
296 | /** |
||
297 | * Set the path to a DSL file for defining |
||
298 | * the test language used |
||
299 | * |
||
300 | * @param string $dsl |
||
301 | * @return $this |
||
302 | */ |
||
303 | public function setDsl($dsl) |
||
307 | |||
308 | /** |
||
309 | * Get the path to a DSL file containing |
||
310 | * test functions to use |
||
311 | * |
||
312 | * @return string |
||
313 | */ |
||
314 | public function getDsl() |
||
318 | |||
319 | /** |
||
320 | * Write a configuration value and persist it to the current |
||
321 | * environment. |
||
322 | * |
||
323 | * @param $varName |
||
324 | * @param $value |
||
325 | * @return $this |
||
326 | */ |
||
327 | protected function write($varName, $value) |
||
335 | |||
336 | /** |
||
337 | * Normalize the supplied regular expression pattern. |
||
338 | * |
||
339 | * @param string $pattern |
||
340 | * @return string |
||
341 | */ |
||
342 | protected function normalizeRegexPattern($pattern) |
||
356 | |||
357 | /** |
||
358 | * Write the reporters and persist them to the current environment. |
||
359 | * |
||
360 | * @param array $reporters |
||
361 | * @return $this |
||
362 | */ |
||
363 | protected function writeReporters(array $reporters) |
||
370 | } |
||
371 |