From 80ff5f5af599f58ea16b7d4535be5a9def0fe817 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 12 Jun 2024 19:13:18 +0200 Subject: [PATCH] Destroy TestCase object after its test was run --- src/Framework/TestSuite.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Framework/TestSuite.php b/src/Framework/TestSuite.php index ad40f4282b..0569786e2c 100644 --- a/src/Framework/TestSuite.php +++ b/src/Framework/TestSuite.php @@ -347,6 +347,30 @@ public function run(): void } $test->run(); + + foreach (array_keys($this->tests) as $key) { + if ($test === $this->tests[$key]) { + unset($this->tests[$key]); + + break; + } + } + + if ($test instanceof TestCase || $test instanceof self) { + foreach ($test->groups() as $group) { + if (!isset($this->groups[$group])) { + continue; + } + + foreach (array_keys($this->groups[$group]) as $key) { + if ($test === $this->groups[$group][$key]) { + unset($this->groups[$group][$key]); + + break; + } + } + } + } } $this->invokeMethodsAfterLastTest($emitter);