1 | <?php |
||
35 | abstract class BrowserTestCase extends TestCase implements IEventDispatcherAware |
||
36 | { |
||
37 | |||
38 | const TEST_ENDED_EVENT = 'test.ended'; |
||
39 | |||
40 | const TEST_SUITE_ENDED_EVENT = 'test_suite.ended'; |
||
41 | |||
42 | const TEST_FAILED_EVENT = 'test.failed'; |
||
43 | |||
44 | const TEST_SETUP_EVENT = 'test.setup'; |
||
45 | |||
46 | /** |
||
47 | * Browser list to be used in tests. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | public static $browsers = array(); |
||
52 | |||
53 | /** |
||
54 | * Event dispatcher. |
||
55 | * |
||
56 | * @var EventDispatcherInterface |
||
57 | */ |
||
58 | private $_eventDispatcher; |
||
59 | |||
60 | /** |
||
61 | * Browser configuration factory. |
||
62 | * |
||
63 | * @var IBrowserConfigurationFactory |
||
64 | */ |
||
65 | private $_browserConfigurationFactory; |
||
66 | |||
67 | /** |
||
68 | * Remote coverage collection url. |
||
69 | * |
||
70 | * @var string Override to provide code coverage data from the server |
||
71 | */ |
||
72 | private $_remoteCoverageScriptUrl; |
||
73 | |||
74 | /** |
||
75 | * Current browser configuration. |
||
76 | * |
||
77 | * @var BrowserConfiguration |
||
78 | */ |
||
79 | private $_browser; |
||
80 | |||
81 | /** |
||
82 | * Reference to Mink session. |
||
83 | * |
||
84 | * @var Session |
||
85 | */ |
||
86 | private $_session; |
||
87 | |||
88 | /** |
||
89 | * Session strategy manager. |
||
90 | * |
||
91 | * @var SessionStrategyManager |
||
92 | */ |
||
93 | protected $sessionStrategyManager; |
||
94 | |||
95 | /** |
||
96 | * Remote coverage helper. |
||
97 | * |
||
98 | * @var RemoteCoverageHelper |
||
99 | */ |
||
100 | protected $remoteCoverageHelper; |
||
101 | |||
102 | /** |
||
103 | * Session strategy, used currently. |
||
104 | * |
||
105 | * @var ISessionStrategy |
||
106 | */ |
||
107 | protected $sessionStrategy; |
||
108 | |||
109 | /** |
||
110 | * Test ID. |
||
111 | * |
||
112 | * @var string |
||
113 | */ |
||
114 | private $_testId; |
||
115 | |||
116 | /** |
||
117 | * Sets application. |
||
118 | * |
||
119 | * @param IBrowserConfigurationFactory $browser_configuration_factory Browser configuration factory. |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | 15 | public function setBrowserConfigurationFactory(IBrowserConfigurationFactory $browser_configuration_factory) |
|
127 | |||
128 | /** |
||
129 | * Sets event dispatcher. |
||
130 | * |
||
131 | * @param EventDispatcherInterface $event_dispatcher Event dispatcher. |
||
132 | * |
||
133 | * @return void |
||
134 | */ |
||
135 | 16 | public function setEventDispatcher(EventDispatcherInterface $event_dispatcher) |
|
139 | |||
140 | /** |
||
141 | * Sets session strategy manager. |
||
142 | * |
||
143 | * @param SessionStrategyManager $session_strategy_manager Session strategy manager. |
||
144 | * |
||
145 | * @return self |
||
146 | */ |
||
147 | 17 | public function setSessionStrategyManager(SessionStrategyManager $session_strategy_manager) |
|
153 | |||
154 | /** |
||
155 | * Sets remote coverage helper. |
||
156 | * |
||
157 | * @param RemoteCoverageHelper $remote_coverage_helper Remote coverage helper. |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | 5 | public function setRemoteCoverageHelper(RemoteCoverageHelper $remote_coverage_helper) |
|
165 | |||
166 | /** |
||
167 | * Sets base url for remote coverage information collection. |
||
168 | * |
||
169 | * @param string $url URL. |
||
170 | * |
||
171 | * @return void |
||
172 | */ |
||
173 | 1 | public function setRemoteCoverageScriptUrl($url) |
|
177 | |||
178 | /** |
||
179 | * Set session meta-info for "Sauce Labs". |
||
180 | * |
||
181 | * @return void |
||
182 | */ |
||
183 | 6 | protected function setUp() |
|
192 | |||
193 | /** |
||
194 | * Sets browser configuration. |
||
195 | * |
||
196 | * @param BrowserConfiguration $browser Browser configuration. |
||
197 | * |
||
198 | * @return self |
||
199 | */ |
||
200 | 11 | public function setBrowser(BrowserConfiguration $browser) |
|
207 | |||
208 | /** |
||
209 | * Returns browser configuration. |
||
210 | * |
||
211 | * @return BrowserConfiguration |
||
212 | * @throws \RuntimeException When browser configuration isn't defined. |
||
213 | */ |
||
214 | 9 | public function getBrowser() |
|
222 | |||
223 | /** |
||
224 | * Initializes a browser with given configuration. |
||
225 | * |
||
226 | * @param array $browser_config Browser configuration. |
||
227 | * |
||
228 | * @return self |
||
229 | */ |
||
230 | 4 | public function setBrowserFromConfiguration(array $browser_config) |
|
234 | |||
235 | /** |
||
236 | * Returns browser configuration instance. |
||
237 | * |
||
238 | * @param array $browser_config Browser. |
||
239 | * |
||
240 | * @return BrowserConfiguration |
||
241 | */ |
||
242 | 4 | protected function createBrowserConfiguration(array $browser_config) |
|
246 | |||
247 | /** |
||
248 | * Sets session strategy. |
||
249 | * |
||
250 | * @param ISessionStrategy $session_strategy Session strategy. |
||
251 | * |
||
252 | * @return self |
||
253 | */ |
||
254 | 14 | public function setSessionStrategy(ISessionStrategy $session_strategy = null) |
|
260 | |||
261 | /** |
||
262 | * Returns session strategy used currently. |
||
263 | * |
||
264 | * @return ISessionStrategy |
||
265 | * @see setSessionStrategy() |
||
266 | */ |
||
267 | 10 | public function getSessionStrategy() |
|
276 | |||
277 | /** |
||
278 | * Creates Mink session using current session strategy and returns it. |
||
279 | * |
||
280 | * @return Session |
||
281 | */ |
||
282 | 4 | public function getSession() |
|
304 | |||
305 | /** |
||
306 | * Runs the test case and collects the results in a TestResult object. |
||
307 | * |
||
308 | * If no TestResult object is passed a new one will be created. |
||
309 | * |
||
310 | * @param TestResult $result Test result. |
||
311 | * |
||
312 | * @return TestResult |
||
313 | */ |
||
314 | 6 | public function run(TestResult $result = null) |
|
338 | |||
339 | /** |
||
340 | * Whatever or not code coverage information should be gathered. |
||
341 | * |
||
342 | * @return boolean |
||
343 | * @throws \RuntimeException When used before test is started. |
||
344 | */ |
||
345 | 7 | public function getCollectCodeCoverageInformation() |
|
355 | |||
356 | /** |
||
357 | * Override to tell remote website, that code coverage information needs to be collected. |
||
358 | * |
||
359 | * @return mixed |
||
360 | */ |
||
361 | 6 | protected function runTest() |
|
373 | |||
374 | /** |
||
375 | * Called, when last test in a test case has ended. |
||
376 | * |
||
377 | * @return self |
||
378 | */ |
||
379 | 3 | public function onTestSuiteEnded() |
|
388 | |||
389 | /** |
||
390 | * Returns remote code coverage information, when enabled. |
||
391 | * |
||
392 | * @return array |
||
393 | */ |
||
394 | 2 | public function getRemoteCodeCoverageInformation() |
|
402 | |||
403 | /** |
||
404 | * Creates test suite for usage with Mink. |
||
405 | * |
||
406 | * @param string $class_name Test case class name. |
||
407 | * |
||
408 | * @return RegularTestSuite |
||
409 | */ |
||
410 | 4 | public static function suite($class_name) |
|
416 | |||
417 | /** |
||
418 | * This method is called when a test method did not execute successfully. |
||
419 | * |
||
420 | * @param \Throwable $e Exception. |
||
421 | * |
||
422 | * @return void |
||
423 | */ |
||
424 | 2 | protected function onNotSuccessfulTest(\Throwable $e) |
|
433 | |||
434 | /** |
||
435 | * Get test id (generated internally). |
||
436 | * |
||
437 | * @return string |
||
438 | */ |
||
439 | 2 | public function getTestId() |
|
443 | |||
444 | /** |
||
445 | * Gets browser configuration aliases. |
||
446 | * |
||
447 | * Allows to decouple actual test server connection details from test cases. |
||
448 | * |
||
449 | * @return array |
||
450 | */ |
||
451 | 2 | public function getBrowserAliases() |
|
455 | |||
456 | } |
||
457 |