11
11
12
12
namespace Symfony \Bridge \PhpUnit \DeprecationErrorHandler ;
13
13
14
+ use PHPUnit \Framework \TestCase ;
15
+ use PHPUnit \Framework \TestSuite ;
14
16
use PHPUnit \Util \Test ;
15
17
use Symfony \Bridge \PhpUnit \Legacy \SymfonyTestsListenerFor ;
16
18
use Symfony \Component \Debug \DebugClassLoader as LegacyDebugClassLoader ;
@@ -82,37 +84,41 @@ public function __construct($message, array $trace, $file)
82
84
}
83
85
}
84
86
85
- if (isset ($ line ['object ' ]) || isset ($ line ['class ' ])) {
86
- if (!isset ($ line ['class ' ], $ trace [$ i - 2 ]['function ' ]) || 0 !== strpos ($ line ['class ' ], SymfonyTestsListenerFor::class)) {
87
- $ this ->originClass = isset ($ line ['object ' ]) ? \get_class ($ line ['object ' ]) : $ line ['class ' ];
88
- $ this ->originMethod = $ line ['function ' ];
87
+ if (!isset ($ line ['object ' ]) && !isset ($ line ['class ' ])) {
88
+ return ;
89
+ }
89
90
90
- return ;
91
- }
91
+ if (!isset ($ line ['class ' ], $ trace [$ i - 2 ]['function ' ]) || 0 !== strpos ($ line ['class ' ], SymfonyTestsListenerFor::class)) {
92
+ $ this ->originClass = isset ($ line ['object ' ]) ? \get_class ($ line ['object ' ]) : $ line ['class ' ];
93
+ $ this ->originMethod = $ line ['function ' ];
92
94
93
- if ('trigger_error ' !== $ trace [$ i - 2 ]['function ' ] || isset ($ trace [$ i - 2 ]['class ' ])) {
94
- $ this ->originClass = \get_class ($ line ['args ' ][0 ]);
95
- $ this ->originMethod = $ line ['args ' ][0 ]->getName ();
95
+ return ;
96
+ }
96
97
97
- return ;
98
- }
98
+ $ test = isset ($ line ['args ' ][0 ]) ? $ line ['args ' ][0 ] : null ;
99
99
100
- set_error_handler (function () {});
101
- $ parsedMsg = unserialize ($ this ->message );
102
- restore_error_handler ();
103
- $ this ->message = $ parsedMsg ['deprecation ' ];
104
- $ this ->originClass = $ parsedMsg ['class ' ];
105
- $ this ->originMethod = $ parsedMsg ['method ' ];
106
- if (isset ($ parsedMsg ['files_stack ' ])) {
107
- $ this ->originalFilesStack = $ parsedMsg ['files_stack ' ];
108
- }
109
- // If the deprecation has been triggered via
110
- // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
111
- // then we need to use the serialized information to determine
112
- // if the error has been triggered from vendor code.
113
- if (isset ($ parsedMsg ['triggering_file ' ])) {
114
- $ this ->triggeringFile = $ parsedMsg ['triggering_file ' ];
115
- }
100
+ if (($ test instanceof TestCase || $ test instanceof TestSuite) && ('trigger_error ' !== $ trace [$ i - 2 ]['function ' ] || isset ($ trace [$ i - 2 ]['class ' ]))) {
101
+ $ this ->originClass = \get_class ($ line ['args ' ][0 ]);
102
+ $ this ->originMethod = $ line ['args ' ][0 ]->getName ();
103
+
104
+ return ;
105
+ }
106
+
107
+ set_error_handler (function () {});
108
+ $ parsedMsg = unserialize ($ this ->message );
109
+ restore_error_handler ();
110
+ $ this ->message = $ parsedMsg ['deprecation ' ];
111
+ $ this ->originClass = $ parsedMsg ['class ' ];
112
+ $ this ->originMethod = $ parsedMsg ['method ' ];
113
+ if (isset ($ parsedMsg ['files_stack ' ])) {
114
+ $ this ->originalFilesStack = $ parsedMsg ['files_stack ' ];
115
+ }
116
+ // If the deprecation has been triggered via
117
+ // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
118
+ // then we need to use the serialized information to determine
119
+ // if the error has been triggered from vendor code.
120
+ if (isset ($ parsedMsg ['triggering_file ' ])) {
121
+ $ this ->triggeringFile = $ parsedMsg ['triggering_file ' ];
116
122
}
117
123
}
118
124
0 commit comments