public function dumpResultToHistory(TestResult $testResult) { $testData = $testResult->toArray(false); // false: don't include zipped artefacts $historyRoot = 'test-history'; if (!is_dir($historyRoot)) { mkdir($historyRoot, 0777, true); } $infoFile = $historyRoot . DIRECTORY_SEPARATOR . 'info.json'; $historyFile = $historyRoot . DIRECTORY_SEPARATOR . 'history.json.stream'; $relativeArtefactsRoot = 'artefacts'; $absoluteArtefactsRoot = $historyRoot . DIRECTORY_SEPARATOR . $relativeArtefactsRoot; if (!is_dir($absoluteArtefactsRoot)) { mkdir($absoluteArtefactsRoot, 0777, true); } $infoHandle = fopen($infoFile, 'c+'); if (!$infoHandle) { throw new Exception('Could not create file: ' + $infoFile); } if (!flock($infoHandle, LOCK_EX)) { throw new Exception('Could not acquire exclusive lock on file: ' + $infoFile); } try { clearstatcache(); $size = filesize($infoFile); $info = $size > 0 ? json_decode(fread($infoHandle, $size), true) : null; if (!$info) { $info = ['historySize' => 0]; } $nextId = $info['historySize']++; $absoluteArtefacts = $absoluteArtefactsRoot . DIRECTORY_SEPARATOR . $nextId; $artefacts = $relativeArtefactsRoot . DIRECTORY_SEPARATOR . $nextId; $testData['historyId'] = $nextId; $testData['artefacts'] = $artefacts; $testResult->unpackArtefactsDir($absoluteArtefacts); file_put_contents($historyFile, json_encode($testData) . "\n", FILE_APPEND | LOCK_EX); ftruncate($infoHandle, 0); rewind($infoHandle); fwrite($infoHandle, json_encode($info)); } finally { flock($infoHandle, LOCK_UN); fclose($infoHandle); } }
public function end(TestInterface $test, TestResult $testResult) { $this->client->send(['type' => 'testEnd', 'planToken' => $this->planToken, 'testIdentifier' => $test->getTestIdentifier(), 'testNumber' => $test->getTestNumber(), 'testResult' => $testResult->toArray()]); return $this; }
public function getInitializedResult() { $testResult = new TestResult(); $testResult->setIdentifierHierarchy([$this->className, $this->name]); return $testResult; }