1 | <?php |
||
20 | abstract class TestCase extends BaseTestCase |
||
21 | { |
||
22 | /** |
||
23 | * Holds drivers fixtures. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $_drivers = []; |
||
28 | |||
29 | /** |
||
30 | * Current Driver for this testcase. |
||
31 | * |
||
32 | * @var Driver |
||
33 | */ |
||
34 | protected $_driver; |
||
35 | |||
36 | /** |
||
37 | * The type of the spiderling driver (kohana, phantomjs ...). |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $_driver_type; |
||
42 | |||
43 | /** |
||
44 | * The Environment object making sure you can set env variables and restore them after the test. |
||
45 | * |
||
46 | * @var \Openbuildings\EnvironmentBackup\Environment |
||
47 | */ |
||
48 | protected $_environment; |
||
49 | |||
50 | /** |
||
51 | * Restore environment and clear the specific driver if its active. |
||
52 | */ |
||
53 | protected function tearDown(): void |
||
54 | 16 | { |
|
55 | if ($this->is_driver_active()) { |
||
56 | 16 | $this->driver()->clear(); |
|
57 | 6 | } |
|
58 | |||
59 | if ($this->is_environment_active()) { |
||
60 | 16 | $this->environment()->restore(); |
|
61 | } |
||
62 | |||
63 | parent::tearDown(); |
||
64 | 16 | } |
|
65 | 16 | ||
66 | /** |
||
67 | * Return the current driver. This will use driver_simple, driver_kohana ... methods |
||
68 | * You can override them yourself in order to have custom configs. |
||
69 | * |
||
70 | * Drivers are cached as fixtured for the whole testrun and is shared between tests. |
||
71 | */ |
||
72 | public function driver(): Driver |
||
86 | |||
87 | public function driver_simple(): Driver_Simple |
||
91 | |||
92 | public function driver_simple_xml(): Driver_SimpleXML |
||
96 | |||
97 | public function driver_kohana(): Driver_Kohana |
||
101 | |||
102 | public function driver_phantomjs(): Driver_Phantomjs |
||
106 | |||
107 | /** |
||
108 | 1 | * Get the type of the driver for the current test. |
|
109 | * Use annotations to change the driver type e.g. @driver phantomjs. |
||
110 | 1 | */ |
|
111 | public function driver_type(): string |
||
121 | |||
122 | 6 | /** |
|
123 | * Return the environment object that handles setting / restoring env variables. |
||
124 | */ |
||
125 | 6 | public function environment(): Environment |
|
137 | |||
138 | /** |
||
139 | * Return true if the driver has been invoked in some way. |
||
140 | */ |
||
141 | public function is_driver_active(): bool |
||
145 | |||
146 | /** |
||
147 | 16 | * Return true if the environment has been modified / accessed. |
|
148 | */ |
||
149 | 16 | public function is_environment_active(): bool |
|
153 | |||
154 | /** |
||
155 | 16 | * Return the root node of the current page, opened by the driver |
|
156 | * Extend it with custom assertions from Assert. |
||
157 | 16 | */ |
|
158 | public function page(): Page |
||
165 | |||
166 | 5 | /** |
|
167 | 5 | * All other methods are handled by the root node of the page. |
|
168 | * |
||
169 | 5 | * @param string $method |
|
170 | * @param array $args |
||
171 | * |
||
172 | * @return mixed |
||
173 | */ |
||
174 | public function __call($method, $args) |
||
178 | |||
179 | private function getDriverFromType(string $type): Driver |
||
198 | } |
||
199 |