15
15
use PHPUnit \Util \ErrorHandler ;
16
16
use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \Configuration ;
17
17
use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \Deprecation ;
18
+ use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \DeprecationGroup ;
18
19
use Symfony \Component \ErrorHandler \DebugClassLoader ;
19
20
20
21
/**
@@ -30,24 +31,20 @@ class DeprecationErrorHandler
30
31
31
32
private $ mode ;
32
33
private $ configuration ;
33
- private $ deprecations = [
34
- 'unsilencedCount ' => 0 ,
35
- 'remaining selfCount ' => 0 ,
36
- 'legacyCount ' => 0 ,
37
- 'otherCount ' => 0 ,
38
- 'remaining directCount ' => 0 ,
39
- 'remaining indirectCount ' => 0 ,
40
- 'unsilenced ' => [],
41
- 'remaining self ' => [],
42
- 'legacy ' => [],
43
- 'other ' => [],
44
- 'remaining direct ' => [],
45
- 'remaining indirect ' => [],
46
- ];
34
+
35
+ /**
36
+ * @var DeprecationGroup[]
37
+ */
38
+ private $ deprecationGroups = [];
47
39
48
40
private static $ isRegistered = false ;
49
41
private static $ isAtLeastPhpUnit83 ;
50
42
43
+ public function __construct ()
44
+ {
45
+ $ this ->resetDeprecationGroups ();
46
+ }
47
+
51
48
/**
52
49
* Registers and configures the deprecation handler.
53
50
*
@@ -135,9 +132,9 @@ public function handleError($type, $msg, $file, $line, $context = [])
135
132
$ group = 'legacy ' ;
136
133
} else {
137
134
$ group = [
138
- Deprecation::TYPE_SELF => 'remaining self ' ,
139
- Deprecation::TYPE_DIRECT => 'remaining direct ' ,
140
- Deprecation::TYPE_INDIRECT => 'remaining indirect ' ,
135
+ Deprecation::TYPE_SELF => 'self ' ,
136
+ Deprecation::TYPE_DIRECT => 'direct ' ,
137
+ Deprecation::TYPE_INDIRECT => 'indirect ' ,
141
138
Deprecation::TYPE_UNDETERMINED => 'other ' ,
142
139
][$ deprecation ->getType ()];
143
140
}
@@ -148,18 +145,14 @@ public function handleError($type, $msg, $file, $line, $context = [])
148
145
exit (1 );
149
146
}
150
147
if ('legacy ' !== $ group ) {
151
- $ ref = &$ this ->deprecations [$ group ][$ msg ]['count ' ];
152
- ++$ ref ;
153
- $ ref = &$ this ->deprecations [$ group ][$ msg ][$ class .':: ' .$ method ];
154
- ++$ ref ;
148
+ $ this ->deprecationGroups [$ group ]->addNoticeFromObject ($ msg , $ class , $ method );
149
+ } else {
150
+ $ this ->deprecationGroups [$ group ]->addNotice ();
155
151
}
156
152
} else {
157
- $ ref = &$ this ->deprecations [$ group ][$ msg ]['count ' ];
158
- ++$ ref ;
153
+ $ this ->deprecationGroups [$ group ]->addNoticeFromProceduralCode ($ msg );
159
154
}
160
155
161
- ++$ this ->deprecations [$ group .'Count ' ];
162
-
163
156
return null ;
164
157
}
165
158
@@ -184,34 +177,44 @@ public function shutdown()
184
177
echo "\n" , self ::colorize ('THE ERROR HANDLER HAS CHANGED! ' , true ), "\n" ;
185
178
}
186
179
187
- $ groups = ['unsilenced ' , 'remaining self ' , 'remaining direct ' , 'remaining indirect ' , 'legacy ' , 'other ' ];
188
-
189
- $ this ->displayDeprecations ($ groups , $ configuration );
180
+ $ groups = array_keys ($ this ->deprecationGroups );
190
181
191
182
// store failing status
192
- $ isFailing = !$ configuration ->tolerates ($ this ->deprecations );
183
+ $ isFailing = !$ configuration ->tolerates ($ this ->deprecationGroups );
193
184
194
- // reset deprecations array
195
- foreach ($ this ->deprecations as $ group => $ arrayOrInt ) {
196
- $ this ->deprecations [$ group ] = \is_int ($ arrayOrInt ) ? 0 : [];
197
- }
185
+ $ this ->displayDeprecations ($ groups , $ configuration , $ isFailing );
186
+
187
+ $ this ->resetDeprecationGroups ();
198
188
199
189
register_shutdown_function (function () use ($ isFailing , $ groups , $ configuration ) {
200
- foreach ($ this ->deprecations as $ group => $ arrayOrInt ) {
201
- if (0 < ( \is_int ( $ arrayOrInt ) ? $ arrayOrInt : \ count ($ arrayOrInt )) ) {
190
+ foreach ($ this ->deprecationGroups as $ group ) {
191
+ if ($ group -> count () > 0 ) {
202
192
echo "Shutdown-time deprecations: \n" ;
203
193
break ;
204
194
}
205
195
}
206
196
207
- $ this ->displayDeprecations ($ groups , $ configuration );
197
+ $ isFailingAtShutdown = !$ configuration ->tolerates ($ this ->deprecationGroups );
198
+ $ this ->displayDeprecations ($ groups , $ configuration , $ isFailingAtShutdown );
208
199
209
- if ($ isFailing || ! $ configuration -> tolerates ( $ this -> deprecations ) ) {
200
+ if ($ isFailing || $ isFailingAtShutdown ) {
210
201
exit (1 );
211
202
}
212
203
});
213
204
}
214
205
206
+ private function resetDeprecationGroups ()
207
+ {
208
+ $ this ->deprecationGroups = [
209
+ 'unsilenced ' => new DeprecationGroup (),
210
+ 'self ' => new DeprecationGroup (),
211
+ 'direct ' => new DeprecationGroup (),
212
+ 'indirect ' => new DeprecationGroup (),
213
+ 'legacy ' => new DeprecationGroup (),
214
+ 'other ' => new DeprecationGroup (),
215
+ ];
216
+ }
217
+
215
218
private function getConfiguration ()
216
219
{
217
220
if (null !== $ this ->configuration ) {
@@ -270,31 +273,38 @@ private static function colorize($str, $red)
270
273
/**
271
274
* @param string[] $groups
272
275
* @param Configuration $configuration
276
+ * @param bool $isFailing
273
277
*/
274
- private function displayDeprecations ($ groups , $ configuration )
278
+ private function displayDeprecations ($ groups , $ configuration, $ isFailing )<
E377
/div>
275
279
{
276
280
$ cmp = function ($ a , $ b ) {
277
- return $ b[ ' count ' ] - $ a[ ' count ' ] ;
281
+ return $ b-> count () - $ a-> count () ;
278
282
};
279
283
280
284
foreach ($ groups as $ group ) {
281
- if ($ this ->deprecations [$ group. ' Count ' ] ) {
285
+ if ($ this ->deprecationGroups [$ group]-> count () ) {
282
286
echo "\n" , self ::colorize (
283
- sprintf ('%s deprecation notices (%d) ' , ucfirst ($ group ), $ this ->deprecations [$ group .'Count ' ]),
284
- 'legacy ' !== $ group && 'remaining indirect ' !== $ group
287
+ sprintf (
288
+ '%s deprecation notices (%d) ' ,
289
+ \in_array ($ group , ['direct ' , 'indirect ' , 'self ' ], true ) ? "Remaining $ group " : ucfirst ($ group ),
290
+ $ this ->deprecationGroups [$ group ]->count ()
291
+ ),
292
+ 'legacy ' !== $ group && 'indirect ' !== $ group
285
293
), "\n" ;
286
294
287
- if (! $ configuration ->verboseOutput () ) {
295
+ if (' legacy ' !== $ group && ! $ configuration ->verboseOutput ($ group ) && ! $ isFailing ) {
288
296
continue ;
289
297
}
290
- uasort ($ this ->deprecations [$ group ], $ cmp );
298
+ $ notices = $ this ->deprecationGroups [$ group ]->notices ();
299
+ uasort ($ notices , $ cmp );
291
300
292
- foreach ($ this -> deprecations [ $ group ] as $ msg => $ notices ) {
293
- echo "\n " , $ notices [ ' count ' ] , 'x: ' , $ msg , "\n" ;
301
+ foreach ($ notices as $ msg => $ notice ) {
302
+ echo "\n " , $ notice -> count () , 'x: ' , $ msg , "\n" ;
294
303
295
- arsort ($ notices );
304
+ $ countsByCaller = $ notice ->getCountsByCaller ();
305
+ arsort ($ countsByCaller );
296
306
297
- foreach ($ notices as $ method => $ count ) {
307
+ foreach ($ countsByCaller as $ method => $ count ) {
298
308
if ('count ' !== $ method ) {
299
309
echo ' ' , $ count , 'x in ' , preg_replace ('/(.*) \\\\(.*?::.*?)$/ ' , '$2 from $1 ' , $ method ), "\n" ;
300
310
}
0 commit comments