Skip to content

Commit 7e798a1

Browse files
fix: handle AfterLastTestMethodErrored in StateGenerator to prevent TypeError in parallel mode
When running tests in parallel mode (--parallel), testErroredEvents() can return AfterLastTestMethodErrored events. The existing code assumed all non-Errored events were BeforeFirstTestMethodErrored, causing a TypeError when an AfterLastTestMethodErrored event was passed to fromBeforeFirstTestMethodErrored(). The fix adds an explicit instanceof check for BeforeFirstTestMethodErrored instead of the catch-all else, allowing AfterLastTestMethodErrored events to be safely skipped. Fixes #1623
1 parent 24d2bf9 commit 7e798a1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/Support/StateGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Event\Code\TestDoxBuilder;
1111
use PHPUnit\Event\Code\TestMethod;
1212
use PHPUnit\Event\Code\ThrowableBuilder;
13+
use PHPUnit\Event\Test\BeforeFirstTestMethodErrored;
1314
use PHPUnit\Event\Test\Errored;
1415
use PHPUnit\Event\Test\Failed;
1516
use PHPUnit\Event\Test\PhpunitDeprecationTriggered;
@@ -34,8 +35,7 @@ public function fromPhpUnitTestResult(int $passedTests, PHPUnitTestResult $testR
3435
TestResult::FAIL,
3536
$testResultEvent->throwable()
3637
));
37-
} else {
38-
// @phpstan-ignore-next-line
38+
} elseif ($testResultEvent instanceof BeforeFirstTestMethodErrored) {
3939
$state->add(TestResult::fromBeforeFirstTestMethodErrored($testResultEvent));
4040
}
4141
}

0 commit comments

Comments
 (0)