15
15
use PHPUnit \Framework \AssertionFailedError ;
16
16
use PHPUnit \Framework \TestCase ;
17
17
use PHPUnit \Framework \TestSuite ;
18
+ use PHPUnit \Runner \BaseTestRunner ;
18
19
use PHPUnit \Util \Blacklist ;
20
+ use PHPUnit \Util \Test ;
19
21
use Symfony \Bridge \PhpUnit \ClockMock ;
20
22
use Symfony \Bridge \PhpUnit \DnsMock ;
21
23
use Symfony \Component \Debug \DebugClassLoader as LegacyDebugClassLoader ;
@@ -48,11 +50,7 @@ class SymfonyTestsListenerTrait
48
50
*/
49
51
public function __construct (array $ mockedNamespaces = array ())
50
52
{
51
- if (class_exists ('PHPUnit_Util_Blacklist ' )) {
52
- \PHPUnit_Util_Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait ' ] = 2 ;
53
- } else {
54
- Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait ' ] = 2 ;
55
- }
53
+ Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait ' ] = 2 ;
56
54
57
55
$ enableDebugClassLoader = class_exists (DebugClassLoader::class) || class_exists (LegacyDebugClassLoader::class);
58
56
@@ -113,19 +111,14 @@ public function globalListenerDisabled()
113
111
114
112
public function startTestSuite ($ suite )
115
113
{
116
- if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
117
- $ Test = 'PHPUnit_Util_Test ' ;
118
- } else {
119
- $ Test = 'PHPUnit\Util\Test ' ;
120
- }
121
114
$ suiteName = $ suite ->getName ();
122
115
$ this ->testsWithWarnings = array ();
123
116
124
117
foreach ($ suite ->tests () as $ test ) {
125
118
if (!($ test instanceof \PHPUnit \Framework \TestCase || $ test instanceof TestCase)) {
126
119
continue ;
127
120
}
128
- if (null === $ Test ::getPreserveGlobalStateSettings (\get_class ($ test ), $ test ->getName (false ))) {
121
+ if (null === Test::getPreserveGlobalStateSettings (\get_class ($ test ), $ test ->getName (false ))) {
129
122
$ test ->setPreserveGlobalState (false );
130
123
}
131
124
}
@@ -157,12 +150,12 @@ public function startTestSuite($suite)
157
150
$ testSuites = array ($ suite );
158
151
for ($ i = 0 ; isset ($ testSuites [$ i ]); ++$ i ) {
159
152
foreach ($ testSuites [$ i ]->tests () as $ test ) {
160
- if ($ test instanceof \PHPUnit_Framework_TestSuite || $ test instanceof TestSuite) {
153
+ if ($ test instanceof TestSuite) {
161
154
if (!class_exists ($ test ->getName (), false )) {
162
155
$ testSuites [] = $ test ;
163
156
continue ;
164
157
}
165
- $ groups = $ Test ::getGroups ($ test ->getName ());
158
+ $ groups = Test::getGroups ($ test ->getName ());
166
159
if (\in_array ('time-sensitive ' , $ groups , true )) {
167
160
ClockMock::register ($ test ->getName ());
168
161
}
@@ -213,14 +206,7 @@ public function startTest($test)
213
206
putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
214
207
}
215
208
216
- if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
217
- $ Test = 'PHPUnit_Util_Test ' ;
218
- $ AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError ' ;
219
- } else {
220
- $ Test = 'PHPUnit\Util\Test ' ;
221
- $ AssertionFailedError = 'PHPUnit\Framework\AssertionFailedError ' ;
222
- }
223
- $ groups = $ Test ::getGroups (\get_class ($ test ), $ test ->getName (false ));
209
+ $ groups = Test::getGroups (\get_class ($ test ), $ test ->getName (false ));
224
210
225
211
if (!$ this ->runsInSeparateProcess ) {
226
212
if (\in_array ('time-sensitive ' , $ groups , true )) {
@@ -232,14 +218,14 @@ public function startTest($test)
232
218
}
233
219
}
234
220
235
- $ annotations = $ Test ::parseTestMethodAnnotations (\get_class ($ test ), $ test ->getName (false ));
221
+ $ annotations = Test::parseTestMethodAnnotations (\get_class ($ test ), $ test ->getName (false ));
236
222
237
223
if (isset ($ annotations ['class ' ]['expectedDeprecation ' ])) {
238
- $ test ->getTestResultObject ()->addError ($ test , new $ AssertionFailedError ('`@expectedDeprecation` annotations are not allowed at the class level. ' ), 0 );
224
+ $ test ->getTestResultObject ()->addError ($ test , new AssertionFailedError ('`@expectedDeprecation` annotations are not allowed at the class level. ' ), 0 );
239
225
}
240
226
if (isset ($ annotations ['method ' ]['expectedDeprecation ' ])) {
241
227
if (!\in_array ('legacy ' , $ groups , true )) {
242
- $ this ->error = new $ AssertionFailedError ('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`. ' );
228
+ $ this ->error = new AssertionFailedError ('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`. ' );
243
229
}
244
230
245
231
$ test ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything (false );
@@ -259,18 +245,8 @@ public function addWarning($test, $e, $time)
259
245
260
246
public function endTest ($ test , $ time )
261
247
{
262
- if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
263
- $ Test = 'PHPUnit_Util_Test ' ;
264
- $ BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner ' ;
265
- $ Warning = 'PHPUnit_Framework_Warning ' ;
266
- } else {
267
- $ Test = 'PHPUnit\Util\Test ' ;
268
- $ BaseTestRunner = 'PHPUnit\Runner\BaseTestRunner ' ;
269
- $ Warning = 'PHPUnit\Framework\Warning ' ;
270
- }
271
248
$ className = \get_class ($ test );
272
- $ classGroups = $ Test ::getGroups ($ className );
273
- $ groups = $ Test ::getGroups ($ className , $ test ->getName (false ));
249
+ $ groups = Test::getGroups ($ className , $ test ->getName (false ));
274
250
275
251
if (null !== $ this ->reportUselessTests ) {
276
252
$ test ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything ($ this ->reportUselessTests );
@@ -299,20 +275,18 @@ public function endTest($test, $time)
299
275
}
300
276
301
277
if ($ this ->expectedDeprecations ) {
302
- if (!\in_array ($ test ->getStatus (), array ($ BaseTestRunner ::STATUS_SKIPPED , $ BaseTestRunner ::STATUS_INCOMPLETE ), true )) {
278
+ if (!\in_array ($ test ->getStatus (), array (BaseTestRunner::STATUS_SKIPPED , BaseTestRunner::STATUS_INCOMPLETE ), true )) {
303
279
$ test ->addToAssertionCount (\count ($ this ->expectedDeprecations ));
304
280
}
305
281
306
282
restore_error_handler ();
307
283
308
- if (!$ errored && !\in_array ($ test ->getStatus (), array ($ BaseTestRunner ::STATUS_SKIPPED , $ BaseTestRunner ::STATUS_INCOMPLETE , $ BaseTestRunner ::STATUS_FAILURE , $ BaseTestRunner ::STATUS_ERROR ), true )) {
284
+ if (!$ errored && !\in_array ($ test ->getStatus (), array (BaseTestRunner::STATUS_SKIPPED , BaseTestRunner::STATUS_INCOMPLETE , BaseTestRunner::STATUS_FAILURE , BaseTestRunner::STATUS_ERROR ), true )) {
309
285
try {
310
286
$ prefix = "@expectedDeprecation: \n" ;
311
287
$ test ->assertStringMatchesFormat ($ prefix .'%A ' .implode ("\n%A " , $ this ->expectedDeprecations )."\n%A " , $ prefix .' ' .implode ("\n " , $ this ->gatheredDeprecations )."\n" );
312
288
} catch (AssertionFailedError $ e ) {
313
289
$ test ->getTestResultObject ()->addFailure ($ test , $ e , $ time );
314
- } catch (\PHPUnit_Framework_AssertionFailedError $ e ) {
315
- $ test ->getTestResultObject ()->addFailure ($ test , $ e , $ time );
316
290
}
317
291
}
318
292
0 commit comments