public static function newReport($id, $sessionId, $referenceId) { if (false === Session::isValidSession($sessionId)) { throw new Exception('Session ID not valid'); } if (false === Reference::isValidResults($referenceId)) { throw new Exception('Reference ID not valid'); } if (!is_numeric($id)) { throw new Exception('Not a valid report ID'); } if (ValidationReport::isValidValidationReport($id)) { throw new Exception('Report already exists'); } $session = new Session($sessionId); $sessionResults = $session->getResults(); $reference = new Reference($referenceId); $referenceResults = $reference->getResults(); // Index the sessionResults so we can look them up $sessionResults['tests'] = array(); foreach ($sessionResults['results'] as $test) { $result = new ResultSupport($test); $testName = $result->getTestName(); if (!array_key_exists($testName, $sessionResults['tests'])) { $sessionResults['tests'][$testName] = array(); } $testId = $test['id']; $sessionResults['tests'][$testName][$testId] = array(); foreach ($test['subtests'] as $subtest) { $subtestName = ResultSupport::getSubtestName($subtest); // Update the results $sessionResults['tests'][$testName][$testId][$subtestName] = $subtest['status']; } } // Test statistics $testsNotRun = 0; $subtestsNotRun = 0; $testsFailed = 0; $subtestsFailed = 0; $log = array(); // Work through each test foreach ($referenceResults['results'] as $test) { $result = new ResultSupport($test); $testName = $result->getTestName(); if (!array_key_exists($testName, $sessionResults['tests'])) { array_push($log, array('type' => 'error', 'message' => 'FAILURE - TEST NOT RUN', 'test' => $testName, 'reference_test_id' => $test['id'])); $testsNotRun++; continue; } if ('testharness' == $result->getTestType()) { // Counter to see if any of the subtests fail $failCheck = $subtestsFailed; foreach ($test['subtests'] as $subtest) { $subtestName = ResultSupport::getSubtestName($subtest); // Check the passed tests if ($subtest['status'] === "PASS") { $testRun = false; foreach ($sessionResults['tests'][$testName] as $testId => $subtestList) { if (array_key_exists($subtestName, $subtestList)) { $testRun = $testId; break; } } if (false === $testRun) { array_push($log, array('type' => 'error', 'message' => 'FAILURE - SUBTEST NOT RUN', 'test' => $testName, 'subtest' => $subtestName, 'reference_test_id' => $test['id'], 'test_ids' => array_keys($sessionResults['tests'][$testName]))); $subtestsNotRun++; continue; } if ($sessionResults['tests'][$testName][$testRun][$subtestName] === "PASS") { //fprintf(STDOUT, " PASS: %s / %s\n", $testName, $subtestName); } else { array_push($log, array('type' => 'error', 'message' => 'FAILURE - SUBTEST FAILED', 'test' => $testName, 'subtest' => $subtestName, 'reference_test_id' => $test['id'], 'test_id' => $testRun)); $subtestsFailed++; } } } // Check if any of the subtests failed if ($failCheck != $subtestsFailed) { $testsFailed++; } } else { } } $status = array('session' => $sessionId, 'reference' => $referenceId, 'tests_not_run' => $testsNotRun, 'subtests_not_run' => $subtestsNotRun, 'tests_failed' => $testsFailed, 'subtests_failed' => $subtestsFailed, 'log_total' => count($log)); $dir = VALIDATION_REPORT_DIR . '/' . $id; mkdir($dir); file_put_contents($dir . '/status', json_encode($status)); file_put_contents($dir . '/report', json_encode($log)); return new ValidationReport($id); }
$app->post('/', function () use($app) { global $status, $statusModified; // Create a new session $report = ValidationReport::newReport($status['reports'], $app->request()->params('session'), $app->request()->params('reference')); $status['reports']++; $statusModified = true; $reportInfo = $report->getInfo(); $reportInfo['href'] = $app->urlFor('reports', array('id' => $report->id)); Notify(ADMIN_TOPIC, array('action' => 'create', 'report' => $reportInfo)); $app->render(200, array('report' => $reportInfo)); }); $app->get('/', function () use($app) { $reports = array(); if ($dh = opendir(VALIDATION_REPORT_DIR)) { while (($file = readdir($dh)) !== false) { if (ValidationReport::isValidValidationReport($file)) { $report = new ValidationReport($file); $reportInfo = $report->getInfo(); $reportInfo['href'] = $app->urlFor('reports', array('id' => $file)); array_push($reports, $reportInfo); } } closedir($dh); } usort($reports, function ($a, $b) { return $a['id'] - $b['id']; }); $app->render(200, array('reports' => $reports)); })->name('reportIndex'); $app->get('/:id', function ($id) use($app) { $report = new ValidationReport($id);