15
15
use PHPUnit \Framework \AssertionFailedError ;
16
16
use PHPUnit \Framework \TestCase ;
17
17
use PHPUnit \Framework \TestSuite ;
18
+ use PHPUnit \Util \Blacklist ;
18
19
use Symfony \Bridge \PhpUnit \ClockMock ;
19
20
use Symfony \Bridge \PhpUnit \DnsMock ;
20
21
@@ -45,6 +46,14 @@ class SymfonyTestsListenerTrait
45
46
*/
46
47
public function __construct (array $ mockedNamespaces = array ())
47
48
{
49
+ if (class_exists ('PHPUnit_Util_Blacklist ' )) {
50
+ \PHPUnit_Util_Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\SymfonyTestsListener ' ] = 1 ;
51
+ \PHPUnit_Util_Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener ' ] = 1 ;
52
+ } else {
53
+ Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\SymfonyTestsListener ' ] = 1 ;
54
+ Blacklist::$ blacklistedClassNames ['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener ' ] = 1 ;
55
+ }
56
+
48
57
foreach ($ mockedNamespaces as $ type => $ namespaces ) {
49
58
if (!is_array ($ namespaces )) {
50
59
$ namespaces = array ($ namespaces );
@@ -82,7 +91,7 @@ public function globalListenerDisabled()
82
91
83
92
public function startTestSuite ($ suite )
84
93
{
85
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
94
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
86
95
$ Test = 'PHPUnit_Util_Test ' ;
87
96
} else {
88
97
$ Test = 'PHPUnit\Util\Test ' ;
@@ -125,6 +134,10 @@ public function startTestSuite($suite)
125
134
if (in_array ('dns-sensitive ' , $ groups , true )) {
126
135
DnsMock::register ($ test ->getName ());
127
136
}
137
+ } elseif (!($ test instanceof \PHPUnit_Framework_TestCase || $ test instanceof TestCase)) {
138
+ // no-op
139
+ } elseif (null === $ Test ::getPreserveGlobalStateSettings (get_class ($ test ), $ test ->getName (false ))) {
140
+ $ test ->setPreserveGlobalState (false );
128
141
}
129
142
}
130
143
}
@@ -135,6 +148,8 @@ public function startTestSuite($suite)
135
148
|| isset ($ this ->wasSkipped [$ suiteName ]['* ' ])
136
149
|| isset ($ this ->wasSkipped [$ suiteName ][$ test ->getName ()])) {
137
150
$ skipped [] = $ test ;
151
+ } elseif (null === $ Test ::getPreserveGlobalStateSettings (get_class ($ test ), $ test ->getName (false ))) {
152
+ $ test ->setPreserveGlobalState (false );
138
153
}
139
154
}
140
155
$ suite ->setTests ($ skipped );
@@ -169,7 +184,7 @@ public function startTest($test)
169
184
putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
170
185
}
171
186
172
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
187
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
173
188
$ Test = 'PHPUnit_Util_Test ' ;
174
189
$ AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError ' ;
175
190
} else {
@@ -215,7 +230,7 @@ public function addWarning($test, $e, $time)
215
230
216
231
public function endTest ($ test , $ time )
217
232
{
218
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
233
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
219
234
$ Test = 'PHPUnit_Util_Test ' ;
220
235
$ BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner ' ;
221
236
$ Warning = 'PHPUnit_Framework_Warning ' ;
0 commit comments