13
13
14
14
use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \Configuration ;
15
15
use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \Deprecation ;
16
+ use Symfony \Bridge \PhpUnit \Legacy \ErrorHandlerCallerV83 ;
16
17
17
18
/**
18
19
* Catch deprecation notices and print a summary report at the end of the test suite.
@@ -49,6 +50,7 @@ class DeprecationErrorHandler
49
50
50
51
private static $ isRegistered = false ;
51
52
private static $ utilPrefix ;
53
+ private static $ isHandlerInvokable ;
52
54
53
55
/**
54
56
* Registers and configures the deprecation handler.
@@ -73,14 +75,16 @@ public static function register($mode = 0)
73
75
}
74
76
75
77
self ::$ utilPrefix = class_exists ('PHPUnit_Util_ErrorHandler ' ) ? 'PHPUnit_Util_ ' : 'PHPUnit\Util \\' ;
78
+ self ::$ isHandlerInvokable = method_exists (self ::$ utilPrefix .'ErrorHandler ' , '__invoke ' );
76
79
77
80
$ handler = new self ();
78
81
$ oldErrorHandler = set_error_handler ([$ handler , 'handleError ' ]);
79
82
80
83
if (null !== $ oldErrorHandler ) {
81
84
restore_error_handler ();
82
85
83
- if ([self ::$ utilPrefix .'ErrorHandler ' , 'handleError ' ] === $ oldErrorHandler ) {
86
+ $ handlerMethod = self ::$ isHandlerInvokable ? '__invoke ' : 'handleError ' ;
87
+ if ([self ::$ utilPrefix .'ErrorHandler ' , $ handlerMethod ] === $ oldErrorHandler ) {
84
88
restore_error_handler ();
85
89
self ::register ($ mode );
86
90
}
@@ -100,12 +104,7 @@ public static function collectDeprecations($outputFile)
100
104
return $ previousErrorHandler ($ type , $ msg , $ file , $ line , $ context );
101
105
}
102
106
103
- static $ autoload = true ;
104
-
105
- $ ErrorHandler = class_exists ('PHPUnit_Util_ErrorHandler ' , $ autoload ) ? 'PHPUnit_Util_ErrorHandler ' : 'PHPUnit\Util\ErrorHandler ' ;
106
- $ autoload = false ;
107
-
108
- return $ ErrorHandler ::handleError ($ type , $ msg , $ file , $ line , $ context );
107
+ return self ::callPhpUnitErrorHandler ($ type , $ msg , $ file , $ line , $ context );
109
108
}
110
109
111
110
$ deprecations [] = [error_reporting (), $ msg , $ file ];
@@ -116,15 +115,25 @@ public static function collectDeprecations($outputFile)
116
115
});
117
116
}
118
117
118
+ private static function callPhpUnitErrorHandler ($ type , $ msg , $ file , $ line , $ context )
119
+ {
120
+ $ ErrorHandler = self ::$ utilPrefix .'ErrorHandler ' ;
121
+ if (self ::$ isHandlerInvokable ) {
122
+ $ handler = new ErrorHandlerCallerV83 ($ _SERVER ['argv ' ]);
123
+
124
+ return $ handler ->handleError ($ type , $ msg , $ file , $ line , $ context );
125
+ }
126
+
127
+ return $ ErrorHandler ::handleError ($ type , $ msg , $ file , $ line , $ context );
128
+ }
129
+
119
130
/**
120
131
* @internal
121
132
*/
122
133
public function handleError ($ type , $ msg , $ file , $ line , $ context = [])
123
134
{
124
135
if ((E_USER_DEPRECATED !== $ type && E_DEPRECATED !== $ type ) || !$ this ->getConfiguration ()->isEnabled ()) {
125
- $ ErrorHandler = self ::$ utilPrefix .'ErrorHandler ' ;
126
-
127
- return $ ErrorHandler ::handleError ($ type , $ msg , $ file , $ line , $ context );
136
+ return static ::callPhpUnitErrorHandler ($ type , $ msg , $ file , $ line , $ context );
128
137
}
129
138
130
139
$ deprecation = new Deprecation ($ msg , debug_backtrace (), $ file );
0 commit comments