Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use const PHP_EOL;
use function array_keys;
use function array_map;
use function array_shift;
use function assert;
use function call_user_func;
use function class_exists;
Expand Down Expand Up @@ -348,38 +349,24 @@ public function run(): void
return;
}

/** @var Test[] $tests Local array, so we clear references to instances asap during the real loop. */
$tests = [];

foreach ($this as $test) {
$tests[] = $test;
}

$this->tests = [];
$this->groups = [];

while ($test = array_shift($tests)) {
if (TestResultFacade::shouldStop()) {
$emitter->testRunnerExecutionAborted();

break;
}

$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);
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/Framework/TestSuiteRunDestructsTestCaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\TestWith;

#[CoversClass(TestSuite::class)]
#[Small]
final class TestSuiteRunDestructsTestCaseTest extends TestCase
{
private static int $destructsDone = 0;

public function __destruct()
{
self::$destructsDone++;
}

public function testFirstTest(): void
{
$this->assertSame(0, self::$destructsDone);
}

#[Depends('testFirstTest')]
public function testSecondTest(): void
{
$this->assertSame(1, self::$destructsDone);
}

#[Depends('testSecondTest')]
#[TestWith([2])]
#[TestWith([3])]
#[TestWith([4])]
public function testThirdTestWhichUsesDataProvider($numberOfTestsBeforeThisOne): void
{
$this->assertSame($numberOfTestsBeforeThisOne, self::$destructsDone);
}
}