4
4
5
5
namespace Codeception \Module ;
6
6
7
+ use Throwable ;
8
+ use function get_debug_type ;
9
+
7
10
/**
8
11
* Special module for using asserts in your tests.
9
12
*/
@@ -31,10 +34,8 @@ class Asserts extends AbstractAsserts
31
34
* $this->doSomethingBad();
32
35
* });
33
36
* ```
34
- *
35
- * @param \Throwable|string $throwable
36
37
*/
37
- public function expectThrowable ($ throwable , callable $ callback ): void
38
+ public function expectThrowable (string | Throwable $ throwable , callable $ callback ): void
38
39
{
39
40
if (is_object ($ throwable )) {
40
41
$ class = get_class ($ throwable );
@@ -48,7 +49,7 @@ public function expectThrowable($throwable, callable $callback): void
48
49
49
50
try {
50
51
$ callback ();
51
- } catch (\ Throwable $ t ) {
52
+ } catch (Throwable $ t ) {
52
53
$ this ->checkThrowable ($ t , $ class , $ msg , $ code );
53
54
return ;
54
55
}
@@ -60,13 +61,13 @@ public function expectThrowable($throwable, callable $callback): void
60
61
* Check if the given throwable matches the expected data,
61
62
* fail (throws an exception) if it does not.
62
63
*/
63
- protected function checkThrowable (\ Throwable $ throwable , string $ expectedClass , ?string $ expectedMsg , $ expectedCode = null ): void
64
+ protected function checkThrowable (Throwable $ throwable , string $ expectedClass , ?string $ expectedMsg , int | null $ expectedCode = null ): void
64
65
{
65
66
if (!($ throwable instanceof $ expectedClass )) {
66
67
$ this ->fail (sprintf (
67
68
"Exception of class '%s' expected to be thrown, but class '%s' was caught " ,
68
69
$ expectedClass ,
69
- get_class ($ throwable )
70
+ get_debug_type ($ throwable )
70
71
));
71
72
}
72
73
0 commit comments