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