/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); $xunitReporter = new XUnit($input->getOption("outputfile")); $incidentReporter = new Incident(); $urls = $this->getUrls($input->getArgument("requestfile")); foreach ($urls as $pageKey => $test) { $harInfo = $harRetriever->getHarFile(new Uri($test["url"])); $htmlContent = $harInfo["html"]; $entries = $harInfo["harFile"]->getEntries(); $currentRequests = array_keys($entries); $requestGroups = $test["requests"]; $requestNotFound = false; foreach ($requestGroups as $groupName => $mandatoryRequests) { foreach ($mandatoryRequests as $mandatoryRequest) { $requestFound = false; foreach ($currentRequests as $currentRequest) { if (preg_match("^" . $mandatoryRequest . "^", $currentRequest)) { $requestFound = true; break; } } if (!$requestFound) { $requestNotFound = true; } $xunitReporter->addTestcase($test["url"], $mandatoryRequest, !$requestFound, $groupName, $pageKey); $incidentReporter->addTestcase($test["url"], $mandatoryRequest, !$requestFound, $groupName, $pageKey); } } if ($requestNotFound && $input->getOption('debugdir') != NULL) { $fileName = $input->getOption('debugdir') . DIRECTORY_SEPARATOR . $pageKey . ".html"; file_put_contents($fileName, $htmlContent); } } $result = $xunitReporter->getReport(); $incidentReporter->getReport(); if ($input->getOption('outputfile') == NULL) { $output->writeln($result); } else { file_put_contents($input->getOption('outputfile'), $result); } }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $testCount = 2; $harRetriever = new HarRetriever(); $xunitReporter = new XUnit($input->getOption('outputfile')); $incidentReporter = new Incident($input->getArgument('apikey')); $urls = $this->getUrls($input->getArgument('requestfile')); $results = array(); foreach ($urls as $pageKey => $test) { for ($i = 0; $i < $testCount; $i++) { try { $harInfo = $harRetriever->getHarFile(new Uri($test['url'])); } catch (PhantomJsRuntimeException $e) { $output->writeln("<error>" . $e->getMessage() . "</error>"); exit($e->getExitCode()); } $htmlContent = $harInfo['html']; $entries = $harInfo['harFile']->getEntries(); $currentRequests = array_keys($entries); $requestGroups = $test['requests']; foreach ($requestGroups as $groupName => $mandatoryRequests) { $groupFailed = false; foreach ($mandatoryRequests as $mandatoryRequest) { $requestFound = false; foreach ($currentRequests as $currentRequest) { if (preg_match('^' . $mandatoryRequest . '^', $currentRequest)) { $requestFound = true; break; } } if (!$requestFound) { $groupFailed = true; } $results[$i][] = array("url" => $test["url"], 'mandatoryRequest' => $mandatoryRequest, 'requestFound' => $requestFound, 'groupName' => $groupName, 'pageKey' => $pageKey, 'htmlContent' => $htmlContent, 'harContent' => json_encode((array) $harInfo['harFile'])); } if ($groupFailed === false) { $output->writeln(" check " . count($mandatoryRequests) . " URLs of '{$pageKey} - {$groupName}' for missing requests. [<info> OK </info>]"); } else { $output->writeln(" check " . count($mandatoryRequests) . " URLs of <error>'{$pageKey} - {$groupName}'</error> for missing requests. <error>[FAIL]</error>"); } } } } foreach ($results[0] as $key => $result) { $requestFound = false; for ($i = 0; $i < $testCount; $i++) { if ($results[$i][$key]['requestFound']) { $requestFound = true; break; } } $xunitReporter->addTestcase($result["url"], $result['mandatoryRequest'], !$requestFound, $result['groupName'], $result['pageKey']); $incidentReporter->addTestcase($result["url"], $result['mandatoryRequest'], !$requestFound, $result['groupName'], $result['pageKey']); if (!$requestFound && $input->getOption('debugdir') != null) { $htmlFileName = $input->getOption('debugdir') . DIRECTORY_SEPARATOR . $result['pageKey'] . '.html'; $harFileName = $input->getOption('debugdir') . DIRECTORY_SEPARATOR . $result['pageKey'] . '.har'; file_put_contents($htmlFileName, $result['htmlContent']); file_put_contents($harFileName, $result['harContent'], JSON_PRETTY_PRINT); } } $result = $xunitReporter->getReport(); $incidentReporter->getReport(); if ($input->getOption('outputfile') == null) { $output->writeln($result); } else { file_put_contents($input->getOption('outputfile'), $result); } }