*/ private array $results = []; private ?string $currentTestId = null; private ?string $currentTestFile = null; private ?float $startTime = null; public function testPrepared(string $testId, ?string $testFile = null): void { $this->currentTestId = $testId; $this->currentTestFile = $testFile; $this->startTime = microtime(true); } public function testPassed(): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::success()); } public function testFailed(string $message): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::failure($message)); } public function testErrored(string $message): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::error($message)); } public function testSkipped(string $message): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::skipped($message)); } public function testIncomplete(string $message): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::incomplete($message)); } public function testRisky(string $message): void { if ($this->currentTestId === null) { return; } $this->record(TestStatus::risky($message)); } /** * @return array */ public function all(): array { return $this->results; } public function recordAssertions(string $testId, int $assertions): void { if (isset($this->results[$testId])) { $this->results[$testId]['assertions'] = $assertions; } } /** * @param array $results */ public function merge(array $results): void { foreach ($results as $testId => $result) { $this->results[$testId] = $result; } } public function reset(): void { $this->results = []; $this->currentTestId = null; $this->currentTestFile = null; $this->startTime = null; } public function finishTest(): void { $this->currentTestId = null; $this->currentTestFile = null; $this->startTime = null; } private function record(TestStatus $status): void { if ($this->currentTestId === null) { return; } $time = $this->startTime !== null ? round(microtime(true) - $this->startTime, 3) : 0.0; $existing = $this->results[$this->currentTestId] ?? null; $this->results[$this->currentTestId] = [ 'status' => $status->asInt(), 'message' => $status->message(), 'time' => $time, 'assertions' => $existing['assertions'] ?? 0, ]; if ($this->currentTestFile !== null) { $this->results[$this->currentTestId]['file'] = $this->currentTestFile; } } }