File tree Expand file tree Collapse file tree 2 files changed +58
-8
lines changed Expand file tree Collapse file tree 2 files changed +58
-8
lines changed Original file line number Diff line number Diff line change 1212use const PHP_EOL ;
1313use function array_keys ;
1414use function array_merge ;
15+ use function array_shift ;
1516use function assert ;
1617use function call_user_func ;
1718use function class_exists ;
@@ -378,22 +379,24 @@ public function run(): void
378379 return ;
379380 }
380381
382+ /** @psalm-var list<Test> $tests */
383+ $ tests = [];
384+
381385 foreach ($ this as $ test ) {
386+ $ tests [] = $ test ;
387+ }
388+
389+ $ this ->tests = [];
390+ $ this ->groups = [];
391+
392+ while ($ test = array_shift ($ tests )) {
382393 if (TestResultFacade::shouldStop ()) {
383394 $ emitter ->testRunnerExecutionAborted ();
384395
385396 break ;
386397 }
387398
388399 $ test ->run ();
389-
390- foreach (array_keys ($ this ->tests ) as $ key ) {
391- if ($ test === $ this ->tests [$ key ]) {
392- unset($ this ->tests [$ key ]);
393-
394- break ;
395- }
396- }
397400 }
398401
399402 $ 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 <[email protected] > 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