@@ -82,6 +82,45 @@ function CLEANUP($uri) {
82
82
}
83
83
}
84
84
85
+ function severityToString ($ type ) {
86
+ switch ($ type ) {
87
+ case E_WARNING :
88
+ return "E_WARNING " ;
89
+ default :
90
+ return "Some other #_ $ type " ;
91
+ }
92
+ }
93
+ function raises (callable $ function , $ type , $ infunction = null ) {
94
+ $ errhandler = function ($ severity , $ message , $ file , $ line , $ errcontext ) {
95
+ throw new ErrorException ($ message , 0 , $ severity , $ file , $ line );
96
+ };
97
+
98
+ set_error_handler ($ errhandler , $ type );
99
+ try {
100
+ $ function ();
101
+ } catch (Exception $ e ) {
102
+ if ($ e instanceof ErrorException && $ e ->getSeverity () & $ type ) {
103
+ if ($ infunction ) {
104
+ $ function = $ e ->getTrace ()[0 ]["function " ];
105
+ if (strcasecmp ($ function , $ infunction ) == 0 ) {
106
+ printf ("OK: Got %s thrown from %s \n" , $ exceptionname , $ infunction );
107
+ } else {
108
+ printf ("ALMOST: Got %s - but was thrown in %s, not %s \n" , $ exceptionname , $ function , $ infunction );
109
+ }
110
+ restore_error_handler ();
111
+ return $ e ->getMessage ();
112
+ }
113
+ printf ("OK: Got %s \n" , severityToString ($ type ));
114
+ } else {
115
+ printf ("ALMOST: Got %s - expected %s \n" , get_class ($ e ), $ exceptionname );
116
+ }
117
+ restore_error_handler ();
118
+ return $ e ->getMessage ();
119
+ }
120
+
121
+ echo "FAILED: Expected $ exceptionname thrown! \n" ;
122
+ restore_error_handler ();
123
+ }
85
124
function throws (callable $ function , $ exceptionname , $ infunction = null ) {
86
125
try {
87
126
$ function ();
0 commit comments