3
3
namespace Kodus \Logging \Test \Unit ;
4
4
5
5
use Codeception \Util \FileSystem ;
6
- use function json_decode ;
7
6
use Kodus \Logging \ChromeLogger ;
7
+ use Kodus \Logging \Test \Fixtures \Bar ;
8
+ use Kodus \Logging \Test \Fixtures \Baz ;
9
+ use Kodus \Logging \Test \Fixtures \Foo ;
8
10
use Mockery ;
9
11
use Mockery \MockInterface ;
12
+ use Nyholm \Psr7 \Response ;
10
13
use Psr \Http \Message \ResponseInterface ;
11
14
use RuntimeException ;
12
- use function str_repeat ;
13
15
use UnitTester ;
14
- use Zend \Diactoros \Response ;
15
-
16
- class Foo
17
- {
18
- public $ foo = "FOO " ;
19
- protected $ bar = "BAR " ;
20
- private $ baz = "BAZ " ;
21
- }
22
-
23
- class Bar extends Foo
24
- {
25
- public $ bat = "BAT " ;
26
- }
27
-
28
- class Baz
29
- {
30
- public $ foo ;
31
- public $ bar ;
32
- public $ baz ;
33
-
34
- public function __construct ()
35
- {
36
- $ this ->foo = new Foo ();
37
- $ this ->bar = new Bar ();
38
- $ this ->baz = $ this ;
39
- }
40
- }
41
16
42
17
class ChromeLoggerCest
43
18
{
44
- public function writeLogMessages (UnitTester $ I )
19
+ public function writeLogMessages (UnitTester $ I ): void
45
20
{
46
21
$ logger = new ChromeLogger ();
47
22
@@ -73,7 +48,7 @@ public function writeLogMessages(UnitTester $I)
73
48
);
74
49
}
75
50
76
- public function serializeContextValues (UnitTester $ I )
51
+ public function serializeContextValues (UnitTester $ I ): void
77
52
{
78
53
$ logger = new ChromeLogger ();
79
54
@@ -129,7 +104,7 @@ public function serializeContextValues(UnitTester $I)
129
104
fclose ($ resource );
130
105
}
131
106
132
- public function obtainStackTrace (UnitTester $ I )
107
+ public function obtainStackTrace (UnitTester $ I ): void
133
108
{
134
109
try {
135
110
$ this ->foo ();
@@ -157,7 +132,7 @@ public function obtainStackTrace(UnitTester $I)
157
132
], $ data ["rows " ]);
158
133
}
159
134
160
- public function renderTables (UnitTester $ I )
135
+ public function renderTables (UnitTester $ I ): void
161
136
{
162
137
$ logger = new ChromeLogger ();
163
138
@@ -178,14 +153,14 @@ public function renderTables(UnitTester $I)
178
153
], $ data ["rows " ]);
179
154
}
180
155
181
- public function truncateExcessiveLogData (UnitTester $ I )
156
+ public function truncateExcessiveLogData (UnitTester $ I ): void
182
157
{
183
158
$ logger = new ChromeLogger ();
184
159
185
160
$ logger ->setLimit (10 *1024 );
186
161
187
162
for ($ n =0 ; $ n <200 ; $ n ++) {
188
- $ message = str_repeat ("0123456789 " , rand (1 ,20 )); // between 10 and 200 bytes
163
+ $ message = str_repeat ("0123456789 " , rand (1 , 20 )); // between 10 and 200 bytes
189
164
190
165
$ logger ->debug ($ message );
191
166
}
@@ -195,7 +170,7 @@ public function truncateExcessiveLogData(UnitTester $I)
195
170
$ I ->assertEquals (ChromeLogger::LIMIT_WARNING , end ($ data ["rows " ])[0 ][0 ]);
196
171
}
197
172
198
- public function persistToLocalFiles (UnitTester $ I )
173
+ public function persistToLocalFiles (UnitTester $ I ): void
199
174
{
200
175
$ logger = new class extends ChromeLogger
201
176
{
@@ -242,7 +217,7 @@ protected function getTime(): int
242
217
$ logger ->debug (str_repeat ("0123456789 " , 20 ));
243
218
}
244
219
245
- $ response = new Response (fopen ("php://temp " , "rw+ " ));
220
+ $ response = new Response (body: fopen ("php://temp " , "rw+ " ));
246
221
247
222
$ response = $ logger ->writeToResponse ($ response );
248
223
@@ -278,7 +253,7 @@ protected function getTime(): int
278
253
"previous {$ num_files } log-files should be garbage-collected " );
279
254
}
280
255
281
- public function allowMultipleLocationHeaders (UnitTester $ I )
256
+ public function allowMultipleLocationHeaders (UnitTester $ I ): void
282
257
{
283
258
$ logger = new ChromeLogger ();
284
259
@@ -294,7 +269,7 @@ public function allowMultipleLocationHeaders(UnitTester $I)
294
269
295
270
$ logger ->info ("TEST " );
296
271
297
- $ response = new Response (fopen ("php://temp " , "rw+ " ));
272
+ $ response = new Response (body: fopen ("php://temp " , "rw+ " ));
298
273
299
274
$ response = $ response ->withHeader ("X-ServerLog-Location " , "/foo " );
300
275
@@ -312,7 +287,7 @@ public function allowMultipleLocationHeaders(UnitTester $I)
312
287
*
313
288
* @return array
314
289
*/
315
- private function extractResult (ChromeLogger $ logger )
290
+ private function extractResult (ChromeLogger $ logger ): array
316
291
{
317
292
/**
318
293
* @var MockInterface|ResponseInterface $response
@@ -336,7 +311,8 @@ private function extractResult(ChromeLogger $logger)
336
311
return json_decode (base64_decode ($ calls [0 ][1 ]), true );
337
312
}
338
313
339
- private function foo () {
314
+ private function foo (): void
315
+ {
340
316
$ this ->bar ();
341
317
}
342
318
0 commit comments