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
$ warn = false ;
49
58
foreach ($ mockedNamespaces as $ type => $ namespaces ) {
50
59
if (!is_array ($ namespaces )) {
@@ -91,7 +100,7 @@ public function globalListenerDisabled()
91
100
92
101
public function startTestSuite ($ suite )
93
102
{
94
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
103
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
95
104
$ Test = 'PHPUnit_Util_Test ' ;
96
105
} else {
97
106
$ Test = 'PHPUnit\Util\Test ' ;
@@ -134,6 +143,10 @@ public function startTestSuite($suite)
134
143
if (in_array ('dns-sensitive ' , $ groups , true )) {
135
144
DnsMock::register ($ test ->getName ());
136
145
}
146
+ } elseif (!($ test instanceof \PHPUnit_Framework_TestCase || $ test instanceof TestCase)) {
147
+ // no-op
148
+ } elseif (null === $ Test ::getPreserveGlobalStateSettings (get_class ($ test ), $ test ->getName (false ))) {
149
+ $ test ->setPreserveGlobalState (false );
137
150
}
138
151
}
139
152
}
@@ -144,6 +157,8 @@ public function startTestSuite($suite)
144
157
|| isset ($ this ->wasSkipped [$ suiteName ]['* ' ])
145
158
|| isset ($ this ->wasSkipped [$ suiteName ][$ test ->getName ()])) {
146
159
$ skipped [] = $ test ;
160
+ } elseif (null === $ Test ::getPreserveGlobalStateSettings (get_class ($ test ), $ test ->getName (false ))) {
161
+ $ test ->setPreserveGlobalState (false );
147
162
}
148
163
}
149
164
$ suite ->setTests ($ skipped );
@@ -178,7 +193,7 @@ public function startTest($test)
178
193
putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
179
194
}
180
195
181
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
196
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
182
197
$ Test = 'PHPUnit_Util_Test ' ;
183
198
$ AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError ' ;
184
199
} else {
@@ -224,7 +239,7 @@ public function addWarning($test, $e, $time)
224
239
225
240
public function endTest ($ test , $ time )
226
241
{
227
- if (class_exists ('PHPUnit_Util_Test ' , false )) {
242
+ if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
228
243
$ Test = 'PHPUnit_Util_Test ' ;
229
244
$ BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner ' ;
230
245
$ Warning = 'PHPUnit_Framework_Warning ' ;
0 commit comments