@@ -39,6 +39,7 @@ class SymfonyTestsListenerTrait
39
39
private $ testsWithWarnings ;
40
40
private $ reportUselessTests ;
41
41
private $ error ;
42
+ private $ runsInSeparateProcess = false ;
42
43
43
44
/**
44
45
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
@@ -183,6 +184,12 @@ public function startTest($test)
183
184
$ this ->reportUselessTests = $ test ->getTestResultObject ()->isStrictAboutTestsThatDoNotTestAnything ();
184
185
}
185
186
187
+ // This event is triggered before the test is re-run in isolation
188
+ if ($ this ->willBeIsolated ($ test )) {
189
+ $ this ->runsInSeparateProcess = tempnam (sys_get_temp_dir (), 'deprec ' );
190
+ putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
191
+ }
192
+
186
193
if (class_exists ('PHPUnit_Util_Blacklist ' , false )) {
187
194
$ Test = 'PHPUnit_Util_Test ' ;
188
195
$ AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError ' ;
@@ -192,12 +199,14 @@ public function startTest($test)
192
199
}
193
200
$ groups = $ Test ::getGroups (get_class ($ test ), $ test ->getName (false ));
194
201
195
- if (in_array ('time-sensitive ' , $ groups , true )) {
196
- ClockMock::register (get_class ($ test ));
197
- ClockMock::withClockMock (true );
198
- }
199
- if (in_array ('dns-sensitive ' , $ groups , true )) {
200
- DnsMock::register (get_class ($ test ));
202
+ if (!$ this ->runsInSeparateProcess ) {
203
+ if (in_array ('time-sensitive ' , $ groups , true )) {
204
+ ClockMock::register (get_class ($ test ));
205
+ ClockMock::withClockMock (true );
206
+ }
207
+ if (in_array ('dns-sensitive ' , $ groups , true )) {
208
+ DnsMock::register (get_class ($ test ));
209
+ }
201
210
}
202
211
203
212
$ annotations = $ Test ::parseTestMethodAnnotations (get_class ($ test ), $ test ->getName (false ));
@@ -245,15 +254,20 @@ public function endTest($test, $time)
245
254
$ this ->reportUselessTests = null ;
246
255
}
247
256
248
- $ errored = false ;
257
+ if ($ errored = null !== $ this ->error ) {
258
+ $ test ->getTestResultObject ()->addError ($ test , $ this ->error , 0 );
259
+ $ this ->error = null ;
260
+ }
249
261
250
- if (null !== $ this ->error ) {
251
- if ($ BaseTestRunner ::STATUS_PASSED === $ test ->getStatus ()) {
252
- $ test ->getTestResultObject ()->addError ($ test , $ this ->error , 0 );
253
- $ errored = true ;
262
+ if ($ this ->runsInSeparateProcess ) {
263
+ foreach (unserialize (file_get_contents ($ this ->runsInSeparateProcess )) as $ deprecation ) {
264
+ if ($ deprecation [0 ]) {
265
+ trigger_error ($ deprecation [1 ], E_USER_DEPRECATED );
266
+ } else {
267
+ @trigger_error ($ deprecation [1 ], E_USER_DEPRECATED );
268
+ }
254
269
}
255
-
256
- $ this ->error = null ;
270
+ $ this ->runsInSeparateProcess = false ;
257
271
}
258
272
259
273
if ($ this ->expectedDeprecations ) {
@@ -277,7 +291,7 @@ public function endTest($test, $time)
277
291
$ this ->expectedDeprecations = $ this ->gatheredDeprecations = array ();
278
292
$ this ->previousErrorHandler = null ;
279
293
}
280
- if (-2 < $ this ->state && ($ test instanceof \PHPUnit_Framework_TestCase || $ test instanceof TestCase)) {
294
+ if (! $ this -> runsInSeparateProcess && -2 < $ this ->state && ($ test instanceof \PHPUnit_Framework_TestCase || $ test instanceof TestCase)) {
281
295
if (in_array ('time-sensitive ' , $ groups , true )) {
282
296
ClockMock::withClockMock (false );
283
297
}
@@ -315,4 +329,21 @@ public function handleError($type, $msg, $file, $line, $context = array())
315
329
}
316
330
$ this ->gatheredDeprecations [] = $ msg ;
317
331
}
332
+
333
+ /**
334
+ * @param Test $test
335
+ *
336
+ * @return bool
337
+ */
338
+ private function willBeIsolated ($ test )
339
+ {
340
+ if ($ test ->isInIsolation ()) {
341
+ return false ;
342
+ }
343
+
344
+ $ r = new \ReflectionProperty ($ test , 'runTestInSeparateProcess ' );
345
+ $ r ->setAccessible (true );
346
+
347
+ return $ r ->getValue ($ test );
348
+ }
318
349
}
0 commit comments