1
- <?php declare (strict_types=1 );
1
+ <?php
2
+
3
+ declare (strict_types=1 );
2
4
3
5
namespace Codeception ;
4
6
8
10
9
11
trait AssertThrows
10
12
{
11
- /**
12
- * @param string|null $message
13
- * @param Throwable $exception
14
- */
15
13
private function checkException (?string $ message , Throwable $ exception )
16
14
{
17
15
$ actualMessage = strtolower ($ exception ->getMessage ());
@@ -32,12 +30,12 @@ private function checkException(?string $message, Throwable $exception)
32
30
/**
33
31
* Asserts that callback throws an exception
34
32
*
35
- * @param $throws
33
+ * @param string|Throwable $throws
36
34
* @param callable $func
37
35
* @param mixed ...$params
38
36
* @throws Throwable
39
37
*/
40
- public function assertThrows ($ throws , callable $ func , ... $ params )
38
+ public function assertThrows ($ throws , callable $ func , array $ params = [] )
41
39
{
42
40
$ this ->assertThrowsWithMessage ($ throws , null , $ func , $ params );
43
41
}
@@ -51,7 +49,7 @@ public function assertThrows($throws, callable $func, ...$params)
51
49
* @param mixed ...$params
52
50
* @throws Throwable
53
51
*/
54
- public function assertThrowsWithMessage ($ throws , ?string $ message , callable $ func , ... $ params )
52
+ public function assertThrowsWithMessage ($ throws , ?string $ message , callable $ func , array $ params = [] )
55
53
{
56
54
if ($ throws instanceof Throwable) {
57
55
$ message = $ throws ->getMessage ();
@@ -63,7 +61,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
63
61
}
64
62
65
63
try {
66
- if ($ params ) {
64
+ if ($ params !== [] ) {
67
65
call_user_func_array ($ func , $ params );
68
66
} else {
69
67
call_user_func ($ func );
@@ -119,7 +117,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
119
117
* @param callable $func
120
118
* @param mixed ...$params
121
119
*/
122
- public function assertDoesNotThrow ($ throws , callable $ func , ... $ params )
120
+ public function assertDoesNotThrow ($ throws , callable $ func , array $ params = [] )
123
121
{
124
122
$ this ->assertDoesNotThrowWithMessage ($ throws , null , $ func , $ params );
125
123
}
@@ -132,15 +130,15 @@ public function assertDoesNotThrow($throws, callable $func, ...$params)
132
130
* @param callable $func
133
131
* @param mixed ...$params
134
132
*/
135
- public function assertDoesNotThrowWithMessage ($ throws , ?string $ message , callable $ func , ... $ params )
133
+ public function assertDoesNotThrowWithMessage ($ throws , ?string $ message , callable $ func , array $ params = [] )
136
134
{
137
135
if ($ throws instanceof Throwable) {
138
136
$ message = $ throws ->getMessage ();
139
137
$ throws = get_class ($ throws );
140
138
}
141
139
142
140
try {
143
- if ($ params ) {
141
+ if ($ params !== [] ) {
144
142
call_user_func_array ($ func , $ params );
145
143
} else {
146
144
call_user_func ($ func );
@@ -165,7 +163,7 @@ public function assertDoesNotThrowWithMessage($throws, ?string $message, callabl
165
163
166
164
$ actualMessage = $ exception ->getMessage ();
167
165
168
- if ($ message != $ actualMessage ) {
166
+ if ($ message !== $ actualMessage ) {
169
167
Assert::assertNotSame ($ message , $ actualMessage );
170
168
return ;
171
169
}
0 commit comments