/**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $harRetriever = new HarRetriever();
     switch ($input->getOption('format')) {
         case 'xunit':
             $reporter = new XUnit($input->getOption('outputfile'));
             break;
         case 'incident':
             $reporter = new Incident();
             break;
         default:
             throw new \RuntimeException('Format (' . $input->getOption('format') . ') not found. ');
     }
     $urls = $this->getUrls($input->getArgument('requestfile'));
     foreach ($urls as $pageKey => $test) {
         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'];
         $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;
                 }
                 $reporter->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 = $reporter->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)
 {
     $harRetriever = new HarRetriever();
     switch ($input->getOption('format')) {
         case 'xunit':
             $reporter = new XUnit($input->getOption("outputfile"));
             break;
         case 'incident':
             $reporter = new Incident();
             break;
         default:
             throw new \RuntimeException("Format (" . $input->getOption('format') . ") not found. ");
     }
     $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;
                 }
                 $reporter->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 = $reporter->getReport();
     if ($input->getOption('outputfile') == NULL) {
         $output->writeln($result);
     } else {
         file_put_contents($input->getOption('outputfile'), $result);
     }
 }
 private function processResult($results, Incident $incidentReporter, $debugDir)
 {
     foreach ($results[0] as $key => $result) {
         $requestFound = false;
         for ($i = 0; $i < self::PROBE_COUNT; $i++) {
             if ($results[$i][$key]['status'] == Reporter::RESPONSE_STATUS_SUCCESS) {
                 $requestFound = true;
                 break;
             }
         }
         $incidentReporter->addTestcase($result["url"], $result['mandatoryRequest'], !$requestFound, $result['groupName'], $result['pageKey'], $result['massage']);
         if (!$requestFound && $debugDir != null) {
             $htmlFileName = $debugDir . DIRECTORY_SEPARATOR . $result['pageKey'] . '.html';
             $harFileName = $debugDir . DIRECTORY_SEPARATOR . $result['pageKey'] . '.har';
             file_put_contents($htmlFileName, $result['htmlContent']);
             file_put_contents($harFileName, $result['harContent'], JSON_PRETTY_PRINT);
         }
     }
     $incidentReporter->getReport();
 }
示例#4
0
 /**
  * @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);
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $testCount = 2;
     $harRetriever = new HarRetriever();
     $projects = $this->getUrls($input->getArgument('url'));
     foreach ($projects as $project) {
         $results = array();
         if ($input->getOption('koalamon_server')) {
             $incidentReporter = new Incident($project['project']->api_key, $input->getOption('koalamon_server'));
         } else {
             $incidentReporter = new Incident($project['project']->api_key);
         }
         foreach ($project['urls'] as $pageKey => $test) {
             $output->writeln('Checking ' . $test['url'] . ' ...');
             for ($i = 0; $i < $testCount; $i++) {
                 try {
                     $harInfo = $harRetriever->getHarFile(new Uri($test['url']), 2000);
                 } catch (PhantomJsRuntimeException $e) {
                     $output->writeln("<error>" . $e->getMessage() . "</error>");
                     continue;
                 }
                 $htmlContent = $harInfo['html'];
                 $entries = $harInfo['harFile']->getEntries();
                 $currentRequests = array_keys($entries);
                 $requestGroups = $test['requests'];
                 foreach ($requestGroups as $groupName => $mandatoryRequests) {
                     foreach ($mandatoryRequests as $mandatoryRequest) {
                         $requestFound = false;
                         foreach ($currentRequests as $currentRequest) {
                             if (preg_match('^' . $mandatoryRequest . '^', $currentRequest)) {
                                 $requestFound = true;
                                 break;
                             }
                         }
                         $results[$i][] = array("url" => $test["url"], 'mandatoryRequest' => $mandatoryRequest, 'requestFound' => $requestFound, 'groupName' => $groupName, 'pageKey' => $pageKey, 'htmlContent' => $htmlContent, 'harContent' => json_encode((array) $harInfo['harFile']));
                     }
                 }
             }
         }
         if (count($results) == 0) {
             continue;
         }
         foreach ($results[0] as $key => $result) {
             $requestFound = false;
             for ($i = 0; $i < $testCount; $i++) {
                 if ($results[$i][$key]['requestFound']) {
                     $requestFound = true;
                     break;
                 }
             }
             $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);
             }
         }
         $incidentReporter->getReport();
     }
 }