Skip to content

Commit 0d93f08

Browse files
committed
refactor(CaseRunner, SuiteRunner): handle test execution errors
1 parent 2e2dee7 commit 0d93f08

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Test/Runner/CaseRunner.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Testo\Test\Dto\CaseResult;
1313
use Testo\Test\Dto\Status;
1414
use Testo\Test\Dto\TestInfo;
15+
use Testo\Test\Dto\TestResult;
1516

1617
final class CaseRunner
1718
{
@@ -47,20 +48,29 @@ public function run(CaseInfo $info): CaseResult
4748
$results = [];
4849
$status = Status::Passed;
4950
foreach ($info->definition->tests->getTests() as $name => $testDefinition) {
50-
$testInfo = new TestInfo(
51-
name: $name,
52-
caseInfo: $info,
53-
testDefinition: $testDefinition,
54-
);
51+
try {
52+
$testInfo = new TestInfo(
53+
name: $name,
54+
caseInfo: $info,
55+
testDefinition: $testDefinition,
56+
);
5557

56-
$result = $this->testRunner->runTest($testInfo);
57-
$result->status->isFailure() and $status = Status::Failed;
58+
$result = $this->testRunner->runTest($testInfo);
59+
$result->status->isFailure() and $status = Status::Failed;
5860

59-
$results[] = $result;
61+
$results[] = $result;
62+
} catch (\Throwable $throwable) {
63+
$status = Status::Error;
64+
isset($testInfo) and $results[] = new TestResult(
65+
info: $testInfo,
66+
status: Status::Error,
67+
failure: $throwable,
68+
);
69+
}
6070
}
6171

6272
return new CaseResult(
63-
$results,
73+
results: $results,
6474
status: $status,
6575
);
6676
}

src/Test/Runner/SuiteRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function run(SuiteInfo $suite, Filter $filter): SuiteResult
6363
$results[] = $result;
6464
} catch (\Throwable) {
6565
// Skip for now
66-
$status = Status::Failed;
66+
$status = Status::Error;
6767
}
6868
}
6969

0 commit comments

Comments
 (0)