Skip to content

Commit 4472c94

Browse files
Merge branch '10.5' into 11.2
2 parents 2b88987 + b2f136f commit 4472c94

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

src/Framework/TestSuite.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use const PHP_EOL;
1313
use function array_keys;
1414
use function array_merge;
15+
use function array_shift;
1516
use function assert;
1617
use function call_user_func;
1718
use 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);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)