-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_exception_handling.php
38 lines (34 loc) · 1.04 KB
/
test_exception_handling.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php declare(strict_types=1);
mt_srand(time(true));
class AnotherException extends Exception { }
/**
* @exception RuntimeException
*/
function test_exceptions_1() : void {
assert_true(true, "yep it's true");
throw new RuntimeException("this is okay because we defined RuntimeException as okay");
}
/**
* @exception RuntimeException
* @exception Exception
* @exception AnotherException
*/
function test_exceptions_2() : void {
assert_true(true, "yep it's true");
$type = mt_rand(1,3);
// echo "exception type: $type";
if ($type == 1) {
throw new RuntimeException("this is okay because we defined RuntimeException as okay");
} else if ($type == 2) {
throw new Exception("this is okay because we also defined Exception as okay");
} else if ($type == 3) {
throw new AnotherException("unexpected exception");
}
}
/**
* an example of failing a test with an Exception
*/
function test_exceptions_3() : void {
assert_true(true, "test passes");
// throw new RuntimeException("test failed!\n");
}