44
55namespace Codeception \Module ;
66
7+ use Throwable ;
8+ use function get_debug_type ;
9+
710/**
811 * Special module for using asserts in your tests.
912 */
@@ -31,10 +34,8 @@ class Asserts extends AbstractAsserts
3134 * $this->doSomethingBad();
3235 * });
3336 * ```
34- *
35- * @param \Throwable|string $throwable
3637 */
37- public function expectThrowable ($ throwable , callable $ callback ): void
38+ public function expectThrowable (string | Throwable $ throwable , callable $ callback ): void
3839 {
3940 if (is_object ($ throwable )) {
4041 $ class = get_class ($ throwable );
@@ -48,7 +49,7 @@ public function expectThrowable($throwable, callable $callback): void
4849
4950 try {
5051 $ callback ();
51- } catch (\ Throwable $ t ) {
52+ } catch (Throwable $ t ) {
5253 $ this ->checkThrowable ($ t , $ class , $ msg , $ code );
5354 return ;
5455 }
@@ -60,13 +61,13 @@ public function expectThrowable($throwable, callable $callback): void
6061 * Check if the given throwable matches the expected data,
6162 * fail (throws an exception) if it does not.
6263 */
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
6465 {
6566 if (!($ throwable instanceof $ expectedClass )) {
6667 $ this ->fail (sprintf (
6768 "Exception of class '%s' expected to be thrown, but class '%s' was caught " ,
6869 $ expectedClass ,
69- get_class ($ throwable )
70+ get_debug_type ($ throwable )
7071 ));
7172 }
7273
0 commit comments