Skip to content

Commit 7099a17

Browse files
Merge branch '10.5' into 11.2
2 parents ab3f057 + 1d079a3 commit 7099a17

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Framework/TestSuite.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TestSuite implements IteratorAggregate, Reorderable, SelfDescribing, Test
8181
*/
8282
private ?array $providedTests = null;
8383
private ?Factory $iteratorFilter = null;
84+
private bool $wasRun = false;
8485

8586
/**
8687
* @psalm-param non-empty-string $name
@@ -346,6 +347,14 @@ public function collect(): array
346347
*/
347348
public function run(): void
348349
{
350+
if ($this->wasRun) {
351+
// @codeCoverageIgnoreStart
352+
throw new Exception('The tests aggregated by this TestSuite were already run');
353+
// @codeCoverageIgnoreEnd
354+
}
355+
356+
$this->wasRun = true;
357+
349358
if (count($this) === 0) {
350359
return;
351360
}
@@ -367,6 +376,30 @@ public function run(): void
367376
}
368377

369378
$test->run();
379+
380+
foreach (array_keys($this->tests) as $key) {
381+
if ($test === $this->tests[$key]) {
382+
unset($this->tests[$key]);
383+
384+
break;
385+
}
386+
}
387+
388+
if ($test instanceof TestCase || $test instanceof self) {
389+
foreach ($test->groups() as $group) {
390+
if (!isset($this->groups[$group])) {
391+
continue;
392+
}
393+
394+
foreach (array_keys($this->groups[$group]) as $key) {
395+
if ($test === $this->groups[$group][$key]) {
396+
unset($this->groups[$group][$key]);
397+
398+
break;
399+
}
400+
}
401+
}
402+
}
370403
}
371404

372405
$this->invokeMethodsAfterLastTest($emitter);

0 commit comments

Comments
 (0)