1515use PHPUnit \Framework \AssertionFailedError ;
1616use PHPUnit \Framework \TestCase ;
1717use PHPUnit \Framework \TestSuite ;
18+ use PHPUnit \Runner \BaseTestRunner ;
1819use PHPUnit \Util \Blacklist ;
20+ use PHPUnit \Util \Test ;
1921use Symfony \Bridge \PhpUnit \ClockMock ;
2022use Symfony \Bridge \PhpUnit \DnsMock ;
2123use Symfony \Component \Debug \DebugClassLoader as LegacyDebugClassLoader ;
@@ -48,11 +50,7 @@ class SymfonyTestsListenerTrait
4850 */
4951 public function __construct (array $ mockedNamespaces = array ())
5052 {
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 ;
5654
5755 $ enableDebugClassLoader = class_exists (DebugClassLoader::class) || class_exists (LegacyDebugClassLoader::class);
5856
@@ -113,19 +111,14 @@ public function globalListenerDisabled()
113111
114112 public function startTestSuite ($ suite )
115113 {
116- if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
117- $ Test = 'PHPUnit_Util_Test ' ;
118- } else {
119- $ Test = 'PHPUnit\Util\Test ' ;
120- }
121114 $ suiteName = $ suite ->getName ();
122115 $ this ->testsWithWarnings = array ();
123116
124117 foreach ($ suite ->tests () as $ test ) {
125118 if (!($ test instanceof \PHPUnit \Framework \TestCase || $ test instanceof TestCase)) {
126119 continue ;
127120 }
128- if (null === $ Test ::getPreserveGlobalStateSettings (\get_class ($ test ), $ test ->getName (false ))) {
121+ if (null === Test::getPreserveGlobalStateSettings (\get_class ($ test ), $ test ->getName (false ))) {
129122 $ test ->setPreserveGlobalState (false );
130123 }
131124 }
@@ -157,12 +150,12 @@ public function startTestSuite($suite)
157150 $ testSuites = array ($ suite );
158151 for ($ i = 0 ; isset ($ testSuites [$ i ]); ++$ i ) {
159152 foreach ($ testSuites [$ i ]->tests () as $ test ) {
160- if ($ test instanceof \PHPUnit_Framework_TestSuite || $ test instanceof TestSuite) {
153+ if ($ test instanceof TestSuite) {
161154 if (!class_exists ($ test ->getName (), false )) {
162155 $ testSuites [] = $ test ;
163156 continue ;
164157 }
165- $ groups = $ Test ::getGroups ($ test ->getName ());
158+ $ groups = Test::getGroups ($ test ->getName ());
166159 if (\in_array ('time-sensitive ' , $ groups , true )) {
167160 ClockMock::register ($ test ->getName ());
168161 }
@@ -213,14 +206,7 @@ public function startTest($test)
213206 putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
214207 }
215208
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 ));
224210
225211 if (!$ this ->runsInSeparateProcess ) {
226212 if (\in_array ('time-sensitive ' , $ groups , true )) {
@@ -232,14 +218,14 @@ public function startTest($test)
232218 }
233219 }
234220
235- $ annotations = $ Test ::parseTestMethodAnnotations (\get_class ($ test ), $ test ->getName (false ));
221+ $ annotations = Test::parseTestMethodAnnotations (\get_class ($ test ), $ test ->getName (false ));
236222
237223 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 );
239225 }
240226 if (isset ($ annotations ['method ' ]['expectedDeprecation ' ])) {
241227 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`. ' );
243229 }
244230
245231 $ test ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything (false );
@@ -259,18 +245,8 @@ public function addWarning($test, $e, $time)
259245
260246 public function endTest ($ test , $ time )
261247 {
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- }
271248 $ 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 ));
274250
275251 if (null !== $ this ->reportUselessTests ) {
276252 $ test ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything ($ this ->reportUselessTests );
@@ -299,20 +275,18 @@ public function endTest($test, $time)
299275 }
300276
301277 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 )) {
303279 $ test ->addToAssertionCount (\count ($ this ->expectedDeprecations ));
304280 }
305281
306282 restore_error_handler ();
307283
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 )) {
309285 try {
310286 $ prefix = "@expectedDeprecation: \n" ;
311287 $ test ->assertStringMatchesFormat ($ prefix .'%A ' .implode ("\n%A " , $ this ->expectedDeprecations )."\n%A " , $ prefix .' ' .implode ("\n " , $ this ->gatheredDeprecations )."\n" );
312288 } catch (AssertionFailedError $ e ) {
313289 $ test ->getTestResultObject ()->addFailure ($ test , $ e , $ time );
314- } catch (\PHPUnit_Framework_AssertionFailedError $ e ) {
315- $ test ->getTestResultObject ()->addFailure ($ test , $ e , $ time );
316290 }
317291 }
318292
0 commit comments