public function assertNumberOfFailures($expectedCount, $jsonTestResults) { $results = Json::decode($jsonTestResults); $count = 0; foreach ($results as $worker) { foreach ($worker as $testResult) { if ($testResult['errors']) { $count++; } } } $this->assertEquals($expectedCount, $count); }
public function getTestsFromReplay($file, $worker) { $resultsRaw = Json::decode(file_get_contents($file)); if (!isset($resultsRaw[$worker])) { throw new \RuntimeException("Invalid worker id, available in this dump are : " . implode(", ", array_keys($resultsRaw))); } $results = new ResultList($worker, $resultsRaw[$worker]); $tests = []; /** @var TestResult $result */ foreach ($results as $result) { $tests[] = new TestRequest($result->getId(), $result->getClass(), $result->getFilename(), $result->getName()); } return $tests; }
private function completeResponse(Response $response, $result) { // Todo PSR logging if ($this->debug) { echo date('r') . ": -> "; print_r($result); } if ($result instanceof ControllerResponse) { $result->send($response); } else { $result = Json::pretty($result); $response->writeHead(200, ['Content-Type' => 'application/json']); $response->end($result); } }
public function testFailed($testNumber, $filename, array $errors) { $this->output->writeln(Json::encode([$filename => $errors])); }
public function save() { $file = Json::pretty(['bootstrap' => $this->bootstrap, 'emitLevel' => $this->emitLevel]); file_put_contents($this->configFilename, $file); }
/** * @param WorkerClient[] $workers * @param OutputFormatter $formatter * @param array $files * @return int */ private function lintFiles(array $workers, OutputFormatter $formatter, array $files) { $count = count($files); $formatter->begin($count); $exit_status = self::SUCCESS; $testNumber = 0; while (true) { $all_idle = true; foreach ($workers as $worker) { if (!$worker->isBusy()) { if (!empty($files)) { $worker->sendTask(array_pop($files)); $all_idle = false; } } else { $all_idle = false; if ($error = $worker->readAllError()) { $formatter->testFailed($testNumber, $worker->getCurrentFile(), [new Error("Error from worker: {$error}")]); $worker->stop(); continue; } if ($result = $worker->getResult()) { $testNumber++; try { $decoded = Json::decode($result); if (!is_array($decoded)) { $formatter->testFailed($testNumber, $worker->getCurrentFile(), [new Error("Invalid response from worker: {$result}")]); $exit_status = 1; continue; } foreach ($decoded as $file => $errors) { if (is_array($errors)) { $exit_status = self::ERROR; $converted_errors = []; foreach ($errors as $error) { $converted_errors[] = new Error($error); } $formatter->testFailed($testNumber, $file, $converted_errors); } else { $formatter->testPassed($testNumber, $file); } } } catch (InvalidJsonException $e) { $result .= $worker->readAll(); $formatter->testFailed($testNumber, $worker->getCurrentFile(), [new Error('Communication error with worker:' . $result)]); $worker->stop(); $exit_status = 1; } } } } if ($all_idle && empty($files)) { foreach ($workers as $worker) { if ($worker->isRunning()) { $stdout = $worker->readAll(); $stderr = $worker->readAllError(); if ($stdout || $stderr) { $formatter->testFailed($testNumber, $worker->getCurrentFile(), [new Error("Worker error: \n" . $stdout . $stderr)]); $exit_status = 1; } } } break; } usleep(10000.0); } $formatter->end($exit_status); return $exit_status; }
/** * @param array $results * @return ResultList[][] */ private function loadRuns(array $results) { foreach ($results as $resultFile) { if (!file_exists($resultFile) || !is_readable($resultFile)) { throw new \RuntimeException("Unable to read input file {$resultFile}"); } (yield $this->loadResults(Json::decode(file_get_contents($resultFile)))); } }
public function toJson() { return Json::encode($this->toArray()); }
public function encode() { return Json::encode($this->toArray()) . "\n"; }
public function end() { $this->output->writeln(Json::encode($this->json)); }