File tree Expand file tree Collapse file tree 2 files changed +58
-24
lines changed Expand file tree Collapse file tree 2 files changed +58
-24
lines changed Original file line number Diff line number Diff line change 12
12
use const PHP_EOL ;
13
13
use function array_keys ;
14
14
use function array_map ;
15
+ use function array_shift ;
15
16
use function assert ;
16
17
use function call_user_func ;
17
18
use function class_exists ;
@@ -348,38 +349,24 @@ public function run(): void
348
349
return ;
349
350
}
350
351
352
+ /** @var Test[] $tests Local array, so we clear references to instances asap during the real loop. */
353
+ $ tests = [];
354
+
351
355
foreach ($ this as $ test ) {
356
+ $ tests [] = $ test ;
357
+ }
358
+
359
+ $ this ->tests = [];
360
+ $ this ->groups = [];
361
+
362
+ while ($ test = array_shift ($ tests )) {
352
363
if (TestResultFacade::shouldStop ()) {
353
364
$ emitter ->testRunnerExecutionAborted ();
354
365
355
366
break ;
356
367
}
357
368
358
369
$ test ->run ();
359
-
360
- foreach (array_keys ($ this ->tests ) as $ key ) {
361
- if ($ test === $ this ->tests [$ key ]) {
362
- unset($ this ->tests [$ key ]);
363
-
364
- break ;
365
- }
366
- }
367
-
368
- if ($ test instanceof TestCase || $ test instanceof self) {
369
- foreach ($ test ->groups () as $ group ) {
370
- if (!isset ($ this ->groups [$ group ])) {
371
- continue ;
372
- }
373
-
374
- foreach (array_keys ($ this ->groups [$ group ]) as $ key ) {
375
- if ($ test === $ this ->groups [$ group ][$ key ]) {
376
- unset($ this ->groups [$ group ][$ key ]);
377
-
378
- break ;
379
- }
380
- }
381
- }
382
- }
383
370
}
384
371
385
372
$ this ->invokeMethodsAfterLastTest ($ emitter );
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \Framework ;
11
+
12
+ use PHPUnit \Framework \Attributes \CoversClass ;
13
+ use PHPUnit \Framework \Attributes \Depends ;
14
+ use PHPUnit \Framework \Attributes \Small ;
15
+ use PHPUnit \Framework \Attributes \TestWith ;
16
+
17
+ #[CoversClass(TestSuite::class)]
18
+ #[Small]
19
+ final class TestSuiteRunDestructsTestCaseTest extends TestCase
20
+ {
21
+ private static int $ destructsDone = 0 ;
22
+
23
+ public function __destruct ()
24
+ {
25
+ self ::$ destructsDone ++;
26
+ }
27
+
28
+ public function testFirstTest (): void
29
+ {
30
+ $ this ->assertSame (0 , self ::$ destructsDone );
31
+ }
32
+
33
+ #[Depends('testFirstTest ' )]
34
+ public function testSecondTest (): void
35
+ {
36
+ $ this ->assertSame (1 , self ::$ destructsDone );
37
+ }
38
+
39
+ #[Depends('testSecondTest ' )]
40
+ #[TestWith([2 ])]
41
+ #[TestWith([3 ])]
42
+ #[TestWith([4 ])]
43
+ public function testThirdTestWhichUsesDataProvider ($ numberOfTestsBeforeThisOne ): void
44
+ {
45
+ $ this ->assertSame ($ numberOfTestsBeforeThisOne , self ::$ destructsDone );
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments