/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); $harFile = $harRetriever->getHarFile(new Uri($input->getArgument("url"))); $urls = array_keys($harFile["harFile"]->getEntries()); $output->writeln("\n<info>Scanning " . $input->getArgument("url") . "</info>\n"); foreach ($urls as $url) { $output->writeln(" - " . $url); } $output->writeln("\n<info> " . count($urls) . " requests found</info>\n"); }
/** * @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); } }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); try { $harFile = $harRetriever->getHarFile(new Uri($input->getArgument('url'))); } catch (PhantomJsRuntimeException $e) { $output->writeln("<error>" . $e->getMessage() . "</error>"); exit($e->getExitCode()); } $urls = array_keys($harFile['harFile']->getEntries()); $output->writeln("\n<info>Scanning " . $input->getArgument('url') . "</info>\n"); foreach ($urls as $url) { $output->writeln(' - ' . $url); } $output->writeln("\n<info> " . count($urls) . " requests found</info>\n"); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); $projectApiKey = $input->getOption('koalamon_project_api_key'); $url = $input->getArgument('url'); $collections = json_decode($input->getOption('koalamon_system_collections'), true); if ($input->getOption('koalamon_server')) { $incidentReporter = new Incident($projectApiKey, $input->getOption('koalamon_system_identifier'), $input->getOption('koalamon_system_id'), $input->getOption('koalamon_server')); } else { $incidentReporter = new Incident($projectApiKey, $input->getOption('koalamon_system_identifier', $input->getOption('koalamon_system_id'))); } $output->writeln('Checking ' . $url . ' ...'); for ($i = 0; $i < self::PROBE_COUNT; $i++) { try { $harInfo = $harRetriever->getHarFile(new Uri($url), self::PHANTOM_TIMEOUT); } catch (PhantomJsRuntimeException $e) { $output->writeln("<error>" . $e->getMessage() . "</error>"); exit(1); } $htmlContent = $harInfo['html']; $entries = $harInfo['harFile']->getEntries(); $actualRequests = array_keys($entries); foreach ($collections as $collection) { foreach ($collection['requests'] as $mandatoryRequest) { $name = $mandatoryRequest['name']; $pattern = $mandatoryRequest['pattern']; $count = $mandatoryRequest['count']; $numFound = 0; foreach ($actualRequests as $actualRequest) { if (preg_match('^' . $pattern . '^', $actualRequest)) { $numFound++; } } if ($numFound == $count) { $status = Reporter::RESPONSE_STATUS_SUCCESS; $message = ''; } else { $status = Reporter::RESPONSE_STATUS_FAILURE; $message = 'Requst was found ' . $numFound . ' times. Expected was ' . $count . ' times.'; } $results[$i][] = array("url" => $url, 'mandatoryRequest' => $pattern . " (" . $name . ")", 'status' => $status, 'massage' => $message, 'groupName' => $collection['name'], 'pageKey' => $name, 'htmlContent' => $htmlContent, 'harContent' => json_encode((array) $harInfo['harFile'])); } } } $this->processResult($results, $incidentReporter, $input->getOption('debugdir')); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); $har = $harRetriever->getHarFile(new Uri($input->getArgument("url"))); $urls = array_keys($har->getEntries()); $escapedUrls = array(); foreach ($urls as $url) { $escapedUrls[] = preg_quote($url); } $config["urls"] = array(); $config["urls"][$input->getArgument("identifier")] = array(); $config["urls"][$input->getArgument("identifier")]["url"] = $input->getArgument("url"); $config["urls"][$input->getArgument("identifier")]["requests"]["standard"] = $escapedUrls; $dumper = new Dumper(); $yaml = $dumper->dump($config, 5); // if file already exists append/merge the yaml file_put_contents($input->getArgument("output"), $yaml); $output->writeln("\n<info> Config file was written (" . $input->getArgument("output") . "). " . count($escapedUrls) . " requests found.</info>\n"); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $harRetriever = new HarRetriever(); try { $harInfo = $harRetriever->getHarFile(new Uri($input->getArgument('url'))); } catch (PhantomJsRuntimeException $e) { $output->writeln("<error>" . $e->getMessage() . "</error>"); exit($e->getExitCode()); } $urls = array_keys($harInfo['harFile']->getEntries()); $escapedUrls = array(); foreach ($urls as $url) { $escapedUrls[] = preg_quote($url); } $config['urls'] = array(); $config['urls'][$input->getArgument('identifier')] = array(); $config['urls'][$input->getArgument('identifier')]['url'] = $input->getArgument('url'); $config['urls'][$input->getArgument('identifier')]['requests']['standard'] = $escapedUrls; $dumper = new Dumper(); $yaml = $dumper->dump($config, 5); // if file already exists append/merge the yaml file_put_contents($input->getArgument('output'), $yaml); $output->writeln("\n<info> Config file was written (" . $input->getArgument('output') . '). ' . count($escapedUrls) . " requests found.</info>\n"); }
/** * @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(); } }