예제 #1
0
 public function testRunnerWithoutValidator()
 {
     $urlProvider = new UrlProvider(['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200]]]);
     $client = GuzzleClient::createClient($this->io, ['handler' => $this->mockClient()]);
     $runner = new Runner($urlProvider, $client);
     $resultCollection = $runner->run();
     $this->assertCount(1, $urlProvider->getUrls());
     $this->assertInstanceOf(UrlInfo::class, $urlProvider->getUrls()['google']);
     $this->assertInstanceOf(ResultCollection::class, $resultCollection);
     $this->assertInstanceOf(Result::class, $resultCollection['google']);
     $this->assertEquals(new Result($this->createUrlInfo(false), 200, 0, null, null), $resultCollection['google']);
 }
예제 #2
0
 /**
  * handle.
  *
  * @param Args $args
  * @param IO   $io
  *
  * @return int
  */
 public function handle(Args $args, IO $io)
 {
     $this->configurationLoader->setRootDirectory($args->getOption('config'));
     $config = $this->configurationLoader->loadConfiguration();
     try {
         $urlProvider = new UrlProvider($config);
         $runner = new Runner($urlProvider, GuzzleClient::createClient($io));
         $renderer = RendererFactory::create($args->getOption('format'), $io);
         $results = $runner->run();
         $renderer->render($results);
         if (isset($config['hogosha_portal']['metric_update']) || isset($config['hogosha_portal']['incident_update'])) {
             $pusher = new PusherManager($config, $io);
             $pusher->push($results);
         }
     } catch (BadResponseException $e) {
         $io->writeLine(sprintf('<error>Exception:</error> "%s"', $e->getMessage()));
     } catch (ConfigurationLoadingException $e) {
         $io->writeLine(sprintf('<info>There is no configuration file in</info> "%s"', $this->configurationLoader->getRootDirectory()));
     }
 }