-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
44 lines (38 loc) · 1.13 KB
/
test.php
File metadata and controls
44 lines (38 loc) · 1.13 KB
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
39
40
41
42
43
44
<?php
require_once __DIR__ . '/vendor/autoload.php';
use TryPhp\PredictExceptionTrait;
$executionClass = new class() {
use PredictExceptionTrait;
};
try {
$executionClass->predictException(function () {
}, \Exception::class);
trigger_error('test failed', E_USER_ERROR);
} catch (\Exception $ex) {
if ($ex->getMessage() !== "Capture was expected to throw 'Exception' but did not.") {
trigger_error('test failed', E_USER_ERROR);
}
}
try {
$executionClass->predictException(function () {
throw new Exception('something happened');
}, \Exception::class);
} catch (\Exception $ex) {
trigger_error('test failed', E_USER_ERROR);
}
try {
$executionClass->predictException(function () {
throw new TypeError('something happened');
}, \TypeError::class);
} catch (\Exception $ex) {
trigger_error('test failed', E_USER_ERROR);
}
try {
$executionClass->predictException(function () {
throw new Exception('something happened');
}, \RuntimeException::class);
} catch (\Exception $ex) {
if ($ex->getMessage() !== "Capture threw an Exception. Expected 'RuntimeException', but got 'Exception'.") {
trigger_error('test failed', E_USER_ERROR);
}
}