1 | <?php |
||
26 | abstract class UnitTestFixture |
||
27 | { |
||
28 | /** @type bool @isFailed Indicates test fixture is failed or not */ |
||
29 | public $isFailed = false; |
||
30 | /** @type array @testStack Track of the unit which is currently testing */ |
||
31 | public $testStack = []; |
||
32 | /** @type array @testReport Output of test results */ |
||
33 | public $testReport = []; |
||
34 | /** @type null|array $testExpectations The set of outcomes which is going to be tested */ |
||
35 | public $testExpectations = null; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Begin testing all methods of the fixture |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function test() |
||
59 | |||
60 | /** |
||
61 | * Tests the specified method of the fixture |
||
62 | * |
||
63 | * @param $uName string Name of the method |
||
64 | * @param $uCallback callable Target method |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | public function testUnit($uName, /* callable */ $uCallback) |
||
141 | |||
142 | /** |
||
143 | * Adds test output to the final report |
||
144 | * |
||
145 | * @param $uOperation string Name of the operation |
||
146 | * @param $uIsFailed bool Is test failed or not? |
||
147 | * @param $uMessage mixed Message (optional) |
||
148 | * |
||
149 | * @return void |
||
150 | */ |
||
151 | public function testAddReport($uOperation, $uIsFailed, $uMessage = null) |
||
169 | |||
170 | /** |
||
171 | * SetUp method of the fixture |
||
172 | * |
||
173 | * This method is being executed when the test is started. |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | protected function setUp() |
||
181 | |||
182 | /** |
||
183 | * TearDown method of the fixture |
||
184 | * |
||
185 | * This method is being executed when the test is finished. |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | protected function tearDown() |
||
193 | |||
194 | /** |
||
195 | * Tests if given condition is **not** true |
||
196 | * |
||
197 | * @param $uCondition bool The condition |
||
198 | * @param $uMessage mixed Message (optional) |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | public function assertTrue($uCondition, $uMessage = null) |
||
206 | |||
207 | /** |
||
208 | * Tests if given condition is **not** false |
||
209 | * |
||
210 | * @param $uCondition bool The condition |
||
211 | * @param $uMessage mixed Message (optional) |
||
212 | * |
||
213 | * @return void |
||
214 | */ |
||
215 | public function assertFalse($uCondition, $uMessage = null) |
||
219 | |||
220 | /** |
||
221 | * Tests if given condition is **not** null |
||
222 | * |
||
223 | * @param $uVariable bool The condition |
||
224 | * @param $uMessage mixed Message (optional) |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | public function assertNull($uVariable, $uMessage = null) |
||
232 | |||
233 | /** |
||
234 | * Tests if given condition is null |
||
235 | * |
||
236 | * @param $uVariable bool The condition |
||
237 | * @param $uMessage mixed Message (optional) |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | public function assertNotNull($uVariable, $uMessage = null) |
||
245 | |||
246 | /** |
||
247 | * Tests if given variable derived from given class |
||
248 | * |
||
249 | * @param $uVariable mixed The variable |
||
250 | * @param $uClassName mixed Class name |
||
251 | * @param $uMessage mixed Message (optional) |
||
252 | * |
||
253 | * @return void |
||
254 | */ |
||
255 | public function assertInstanceOf($uVariable, $uClassName, $uMessage = null) |
||
259 | |||
260 | /** |
||
261 | * Tests if given variables have the same type and value |
||
262 | * |
||
263 | * @param $uVariable1 mixed First variable |
||
264 | * @param $uVariable2 mixed Second variable |
||
265 | * @param $uMessage mixed Message (optional) |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function assertSame($uVariable1, $uVariable2, $uMessage = null) |
||
273 | |||
274 | /** |
||
275 | * Tests if given variables have the same value |
||
276 | * |
||
277 | * @param $uVariable1 mixed First variable |
||
278 | * @param $uVariable2 mixed Second variable |
||
279 | * @param $uMessage mixed Message (optional) |
||
280 | * |
||
281 | * @return void |
||
282 | */ |
||
283 | public function assertEquals($uVariable1, $uVariable2, $uMessage = null) |
||
287 | |||
288 | /** |
||
289 | * Tests if given variable is a substring of another given variable |
||
290 | * |
||
291 | * @param $uVariable1 mixed First variable |
||
292 | * @param $uVariable2 mixed Second variable |
||
293 | * @param $uMessage mixed Message (optional) |
||
294 | * |
||
295 | * @return void |
||
296 | */ |
||
297 | public function assertContains($uVariable1, $uVariable2, $uMessage = null) |
||
306 | |||
307 | /** |
||
308 | * Tests if will testing unit throw specified exception or not |
||
309 | * |
||
310 | * @param $uExceptionType string Name of the exception type |
||
311 | * |
||
312 | * @return void |
||
313 | */ |
||
314 | public function expectException($uExceptionType) |
||
318 | |||
319 | /** |
||
320 | * Ignores if testing unit throws specified exception during test |
||
321 | * |
||
322 | * @param $uExceptionType string Name of the exception type |
||
323 | * |
||
324 | * @return void |
||
325 | */ |
||
326 | public function ignoreException($uExceptionType) |
||
330 | |||
331 | /** |
||
332 | * Marks current unit test as skipped |
||
333 | * |
||
334 | * @param $uMessage mixed Message (optional) |
||
335 | * |
||
336 | * @return void |
||
337 | */ |
||
338 | public function markTestSkipped($uMessage = null) |
||
342 | |||
343 | /** |
||
344 | * Marks current unit test as failed |
||
345 | * |
||
346 | * @param $uMessage mixed Message (optional) |
||
347 | * |
||
348 | * @return void |
||
349 | */ |
||
350 | public function fail($uMessage = null) |
||
354 | } |
||
355 |