1- <?php declare (strict_types=1 );
1+ <?php
2+
3+ declare (strict_types=1 );
24
35namespace Codeception ;
46
810
911trait AssertThrows
1012{
11- /**
12- * @param string|null $message
13- * @param Throwable $exception
14- */
1513 private function checkException (?string $ message , Throwable $ exception )
1614 {
1715 $ actualMessage = strtolower ($ exception ->getMessage ());
@@ -32,12 +30,12 @@ private function checkException(?string $message, Throwable $exception)
3230 /**
3331 * Asserts that callback throws an exception
3432 *
35- * @param $throws
33+ * @param string|Throwable $throws
3634 * @param callable $func
3735 * @param mixed ...$params
3836 * @throws Throwable
3937 */
40- public function assertThrows ($ throws , callable $ func , ... $ params )
38+ public function assertThrows ($ throws , callable $ func , array $ params = [] )
4139 {
4240 $ this ->assertThrowsWithMessage ($ throws , null , $ func , $ params );
4341 }
@@ -51,7 +49,7 @@ public function assertThrows($throws, callable $func, ...$params)
5149 * @param mixed ...$params
5250 * @throws Throwable
5351 */
54- public function assertThrowsWithMessage ($ throws , ?string $ message , callable $ func , ... $ params )
52+ public function assertThrowsWithMessage ($ throws , ?string $ message , callable $ func , array $ params = [] )
5553 {
5654 if ($ throws instanceof Throwable) {
5755 $ message = $ throws ->getMessage ();
@@ -63,7 +61,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
6361 }
6462
6563 try {
66- if ($ params ) {
64+ if ($ params !== [] ) {
6765 call_user_func_array ($ func , $ params );
6866 } else {
6967 call_user_func ($ func );
@@ -119,7 +117,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
119117 * @param callable $func
120118 * @param mixed ...$params
121119 */
122- public function assertDoesNotThrow ($ throws , callable $ func , ... $ params )
120+ public function assertDoesNotThrow ($ throws , callable $ func , array $ params = [] )
123121 {
124122 $ this ->assertDoesNotThrowWithMessage ($ throws , null , $ func , $ params );
125123 }
@@ -132,15 +130,15 @@ public function assertDoesNotThrow($throws, callable $func, ...$params)
132130 * @param callable $func
133131 * @param mixed ...$params
134132 */
135- public function assertDoesNotThrowWithMessage ($ throws , ?string $ message , callable $ func , ... $ params )
133+ public function assertDoesNotThrowWithMessage ($ throws , ?string $ message , callable $ func , array $ params = [] )
136134 {
137135 if ($ throws instanceof Throwable) {
138136 $ message = $ throws ->getMessage ();
139137 $ throws = get_class ($ throws );
140138 }
141139
142140 try {
143- if ($ params ) {
141+ if ($ params !== [] ) {
144142 call_user_func_array ($ func , $ params );
145143 } else {
146144 call_user_func ($ func );
@@ -165,7 +163,7 @@ public function assertDoesNotThrowWithMessage($throws, ?string $message, callabl
165163
166164 $ actualMessage = $ exception ->getMessage ();
167165
168- if ($ message != $ actualMessage ) {
166+ if ($ message !== $ actualMessage ) {
169167 Assert::assertNotSame ($ message , $ actualMessage );
170168 return ;
171169 }
0 commit comments