@@ -21,16 +21,16 @@ protected function setUp()
21
21
{
22
22
\ini_set ('display_errors ' , (string ) false );
23
23
$ this ->backupErrorLog = \ini_get ('error_log ' );
24
- $ this ->errorLog = __DIR__ . \DIRECTORY_SEPARATOR . 'error_log_test ' ;
24
+ $ this ->errorLog = __DIR__ . \DIRECTORY_SEPARATOR . 'error_log_test ' ;
25
25
\touch ($ this ->errorLog );
26
26
\ini_set ('error_log ' , $ this ->errorLog );
27
27
28
- $ this ->exception = new ErrorException (\uniqid ('normal_ ' ), \E_USER_NOTICE );
29
- $ this ->emailsSent = [];
30
- $ this ->errorHandler = new ErrorHandler (function ($ subject , $ body ) {
28
+ $ this ->exception = new ErrorException (\uniqid ('normal_ ' ), \E_USER_NOTICE );
29
+ $ this ->emailsSent = [];
30
+ $ this ->errorHandler = new ErrorHandler (function (string $ subject , string $ body ) {
31
31
$ this ->emailsSent [] = [
32
32
'subject ' => $ subject ,
33
- 'body ' => $ body ,
33
+ 'body ' => $ body ,
34
34
];
35
35
});
36
36
@@ -50,26 +50,26 @@ public function testDefaultConfiguration()
50
50
$ errorHandler = new ErrorHandler (function () {
51
51
});
52
52
53
- $ this -> assertTrue ($ errorHandler ->isCli ());
54
- $ this -> assertTrue ($ errorHandler ->autoExit ());
55
- $ this -> assertNotNull ($ errorHandler ->getTerminalWidth ());
56
- $ this -> assertSame (\STDERR , $ errorHandler ->getErrorOutputStream ());
57
- $ this -> assertFalse ($ errorHandler ->logErrors ());
53
+ static :: assertTrue ($ errorHandler ->isCli ());
54
+ static :: assertTrue ($ errorHandler ->autoExit ());
55
+ static :: assertNotNull ($ errorHandler ->getTerminalWidth ());
56
+ static :: assertSame (\STDERR , $ errorHandler ->getErrorOutputStream ());
57
+ static :: assertFalse ($ errorHandler ->logErrors ());
58
58
59
59
$ errorHandler ->setCli (false );
60
60
$ errorHandler ->setAutoExit (false );
61
61
$ errorHandler ->setTerminalWidth ($ width = \mt_rand (1 , 999 ));
62
62
$ errorHandler ->setErrorOutputStream ($ memoryStream = \fopen ('php://memory ' , 'r+ ' ));
63
63
$ errorHandler ->setLogErrors (true );
64
64
65
- $ this -> assertFalse ($ errorHandler ->isCli ());
66
- $ this -> assertFalse ($ errorHandler ->autoExit ());
67
- $ this -> assertSame ($ width , $ errorHandler ->getTerminalWidth ());
68
- $ this -> assertSame ($ memoryStream , $ errorHandler ->getErrorOutputStream ());
69
- $ this -> assertTrue ($ errorHandler ->logErrors ());
65
+ static :: assertFalse ($ errorHandler ->isCli ());
66
+ static :: assertFalse ($ errorHandler ->autoExit ());
67
+ static :: assertSame ($ width , $ errorHandler ->getTerminalWidth ());
68
+ static :: assertSame ($ memoryStream , $ errorHandler ->getErrorOutputStream ());
69
+ static :: assertTrue ($ errorHandler ->logErrors ());
70
70
71
71
$ errorHandler ->setErrorOutputStream (\uniqid ('not_a_stream_ ' ));
72
- $ this -> assertSame ($ memoryStream , $ errorHandler ->getErrorOutputStream ());
72
+ static :: assertSame ($ memoryStream , $ errorHandler ->getErrorOutputStream ());
73
73
}
74
74
75
75
/**
@@ -97,9 +97,9 @@ public function testScream()
97
97
\E_USER_WARNING => true ,
98
98
];
99
99
100
- $ this -> assertEmpty ($ this ->errorHandler ->getScreamSilencedErrors ());
100
+ static :: assertEmpty ($ this ->errorHandler ->getScreamSilencedErrors ());
101
101
$ this ->errorHandler ->setScreamSilencedErrors ($ scream );
102
- $ this -> assertSame ($ scream , $ this ->errorHandler ->getScreamSilencedErrors ());
102
+ static :: assertSame ($ scream , $ this ->errorHandler ->getScreamSilencedErrors ());
103
103
104
104
$ this ->errorHandler ->register ();
105
105
@@ -115,13 +115,14 @@ public function testScream()
115
115
public function testHandleCliException ()
116
116
{
117
117
$ memoryStream = \fopen ('php://memory ' , 'r+ ' );
118
+ static ::assertIsResource ($ memoryStream );
118
119
$ this ->errorHandler ->setErrorOutputStream ($ memoryStream );
119
120
120
121
$ this ->errorHandler ->exceptionHandler ($ this ->exception );
121
122
122
123
\fseek ($ memoryStream , 0 );
123
124
$ output = \stream_get_contents ($ memoryStream );
124
- $ this -> assertContains ($ this ->exception ->getMessage (), $ output );
125
+ static :: assertContains ($ this ->exception ->getMessage (), $ output );
125
126
}
126
127
127
128
public function testHandleWebExceptionWithDisplay ()
@@ -134,10 +135,10 @@ public function testHandleWebExceptionWithDisplay()
134
135
$ this ->errorHandler ->exceptionHandler ($ this ->exception );
135
136
$ output = \ob_get_clean ();
136
137
137
- $ this -> assertContains ($ this ->exception ->getMessage (), $ output );
138
+ static :: assertContains ($ this ->exception ->getMessage (), $ output );
138
139
139
140
$ errorLogContent = \file_get_contents ($ this ->errorLog );
140
- $ this -> assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
141
+ static :: assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
141
142
}
142
143
143
144
public function testHandleWebExceptionWithoutDisplay ()
@@ -150,10 +151,10 @@ public function testHandleWebExceptionWithoutDisplay()
150
151
$ this ->errorHandler ->exceptionHandler ($ this ->exception );
151
152
$ output = \ob_get_clean ();
152
153
153
- $ this -> assertNotContains ($ this ->exception ->getMessage (), $ output );
154
+ static :: assertNotContains ($ this ->exception ->getMessage (), $ output );
154
155
155
156
$ errorLogContent = \file_get_contents ($ this ->errorLog );
156
- $ this -> assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
157
+ static :: assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
157
158
}
158
159
159
160
public function testLogErrorAndException ()
@@ -162,7 +163,7 @@ public function testLogErrorAndException()
162
163
163
164
$ this ->errorHandler ->logException ($ this ->exception );
164
165
165
- $ this -> assertSame (0 , \filesize ($ this ->errorLog ));
166
+ static :: assertSame (0 , \filesize ($ this ->errorLog ));
166
167
167
168
$ this ->errorHandler ->setLogErrors (true );
168
169
@@ -172,8 +173,8 @@ public function testLogErrorAndException()
172
173
173
174
$ errorLogContent = \file_get_contents ($ this ->errorLog );
174
175
175
- $ this -> assertContains ($ exception ->getMessage (), $ errorLogContent );
176
- $ this -> assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
176
+ static :: assertContains ($ exception ->getMessage (), $ errorLogContent );
177
+ static :: assertContains ($ this ->exception ->getMessage (), $ errorLogContent );
177
178
}
178
179
179
180
public function testEmailException ()
@@ -182,54 +183,54 @@ public function testEmailException()
182
183
183
184
$ this ->errorHandler ->emailException ($ this ->exception );
184
185
185
- $ this -> assertEmpty ($ this ->emailsSent );
186
+ static :: assertEmpty ($ this ->emailsSent );
186
187
187
188
$ this ->errorHandler ->setLogErrors (true );
188
189
189
- $ key = \uniqid (__FUNCTION__ );
190
+ $ key = \uniqid (__FUNCTION__ );
190
191
$ _SESSION = [$ key => \uniqid ()];
191
- $ _POST = [$ key => \uniqid ()];
192
+ $ _POST = [$ key => \uniqid ()];
192
193
193
194
$ this ->errorHandler ->emailException ($ this ->exception );
194
195
195
- $ this -> assertNotEmpty ($ this ->emailsSent );
196
+ static :: assertNotEmpty ($ this ->emailsSent );
196
197
$ message = \current ($ this ->emailsSent );
197
- $ this -> assertNotEmpty ($ message );
198
+ static :: assertNotEmpty ($ message );
198
199
199
200
$ messageText = $ message ['body ' ];
200
- $ this -> assertContains ($ this ->exception ->getMessage (), $ messageText );
201
- $ this -> assertContains ($ _SESSION [$ key ], $ messageText );
202
- $ this -> assertContains ($ _POST [$ key ], $ messageText );
201
+ static :: assertContains ($ this ->exception ->getMessage (), $ messageText );
202
+ static :: assertContains ($ _SESSION [$ key ], $ messageText );
203
+ static :: assertContains ($ _POST [$ key ], $ messageText );
203
204
}
204
205
205
206
public function testCanHideVariablesFromEmail ()
206
207
{
207
- $ this -> assertTrue ($ this ->errorHandler ->logVariables ());
208
+ static :: assertTrue ($ this ->errorHandler ->logVariables ());
208
209
$ this ->errorHandler ->setLogVariables (false );
209
- $ this -> assertFalse ($ this ->errorHandler ->logVariables ());
210
+ static :: assertFalse ($ this ->errorHandler ->logVariables ());
210
211
211
212
$ this ->errorHandler ->setLogErrors (true );
212
213
213
- $ key = \uniqid (__FUNCTION__ );
214
+ $ key = \uniqid (__FUNCTION__ );
214
215
$ _SESSION = [$ key => \uniqid ()];
215
- $ _POST = [$ key => \uniqid ()];
216
+ $ _POST = [$ key => \uniqid ()];
216
217
217
218
$ this ->errorHandler ->emailException ($ this ->exception );
218
219
219
- $ this -> assertNotEmpty ($ this ->emailsSent );
220
+ static :: assertNotEmpty ($ this ->emailsSent );
220
221
$ message = \current ($ this ->emailsSent );
221
- $ this -> assertNotEmpty ($ message );
222
+ static :: assertNotEmpty ($ message );
222
223
223
224
$ messageText = $ message ['body ' ];
224
- $ this -> assertContains ($ this ->exception ->getMessage (), $ messageText );
225
- $ this -> assertNotContains ($ _SESSION [$ key ], $ messageText );
226
- $ this -> assertNotContains ($ _POST [$ key ], $ messageText );
225
+ static :: assertContains ($ this ->exception ->getMessage (), $ messageText );
226
+ static :: assertNotContains ($ _SESSION [$ key ], $ messageText );
227
+ static :: assertNotContains ($ _POST [$ key ], $ messageText );
227
228
}
228
229
229
230
public function testErroriNellInvioDellaMailVengonoComunqueLoggati ()
230
231
{
231
- $ mailError = \uniqid ('mail_not_sent_ ' );
232
- $ mailCallback = function ($ body , $ text ) use ($ mailError ) {
232
+ $ mailError = \uniqid ('mail_not_sent_ ' );
233
+ $ mailCallback = static function () use ($ mailError ) {
233
234
throw new ErrorException ($ mailError , \E_USER_ERROR );
234
235
};
235
236
$ errorHandler = new ErrorHandler ($ mailCallback );
@@ -238,8 +239,8 @@ public function testErroriNellInvioDellaMailVengonoComunqueLoggati()
238
239
$ errorHandler ->emailException ($ this ->exception );
239
240
240
241
$ errorLogContent = \file_get_contents ($ this ->errorLog );
241
- $ this -> assertNotContains ($ this ->exception ->getMessage (), $ errorLogContent );
242
- $ this -> assertContains ($ mailError , $ errorLogContent );
242
+ static :: assertNotContains ($ this ->exception ->getMessage (), $ errorLogContent );
243
+ static :: assertContains ($ mailError , $ errorLogContent );
243
244
}
244
245
245
246
public function testUsernameInEmailSubject ()
@@ -252,7 +253,7 @@ public function testUsernameInEmailSubject()
252
253
253
254
$ message = \current ($ this ->emailsSent );
254
255
255
- $ this -> assertContains ($ username , $ message ['subject ' ]);
256
+ static :: assertContains ($ username , $ message ['subject ' ]);
256
257
}
257
258
258
259
public function testTerminalWidthByEnv ()
@@ -263,14 +264,14 @@ public function testTerminalWidthByEnv()
263
264
$ errorHandler = new ErrorHandler (function () {
264
265
});
265
266
266
- $ this -> assertSame ($ width , $ errorHandler ->getTerminalWidth ());
267
+ static :: assertSame ($ width , $ errorHandler ->getTerminalWidth ());
267
268
268
269
\putenv ('COLUMNS ' );
269
270
270
271
$ errorHandler = new ErrorHandler (function () {
271
272
});
272
273
273
274
$ terminal = new Terminal ();
274
- $ this -> assertSame ($ terminal ->getWidth (), $ errorHandler ->getTerminalWidth ());
275
+ static :: assertSame ($ terminal ->getWidth (), $ errorHandler ->getTerminalWidth ());
275
276
}
276
277
}
0 commit comments