/** * testDefaultConfigurationFile. */ public function testDefaultConfigurationFile() { $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . Monitor::CONFIG_FILENAME; $configurationLoader = new ConfigurationLoader(); $configurationDumper = new ConfigurationDumper(); $filesystem = new Filesystem(); $argsMock = $this->prophesize(Args::class); $argsMock->getOption(Argument::type('string'))->willReturn(sys_get_temp_dir()); $ioMock = $this->prophesize(IO::class); $ioMock->writeLine(Argument::type('string'))->shouldBeCalled(); $commandMock = $this->prophesize(Command::class); $initHandler = new InitHandler($configurationLoader, $configurationDumper, $filesystem); $initHandler->handle($argsMock->reveal(), $ioMock->reveal(), $commandMock->reveal()); // Test the configuration of the enduser file $this->assertEquals($testFile, $configurationLoader->getConfigurationFilepath()); $this->assertEquals(['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200, 'metric_uuid' => null, 'service_uuid' => null]], 'hogosha_portal' => ['username' => '', 'password' => '', 'base_uri' => 'http://localhost:8000/api/', 'metric_update' => false, 'incident_update' => false, 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', 'default_resolved_incident_message' => 'The service %service_name% is back to normal']], Yaml::parse(file_get_contents($testFile))); unlink($testFile); }
/** * handle. * * @param Args $args * @param IO $io * * @return int */ public function handle(Args $args, IO $io) { $configFileExist = true; $overwrite = is_string($args->getOption('force')); try { $this->configurationLoader->setRootDirectory($args->getOption('config')); $configuration = $this->configurationLoader->loadConfiguration(); } catch (ConfigurationLoadingException $e) { $configFileExist = false; } if (!$configFileExist || $overwrite) { $configuration = ['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200, 'metric_uuid' => null, 'service_uuid' => null]], 'hogosha_portal' => ['username' => '', 'password' => '', 'base_uri' => 'http://localhost:8000/api/', 'metric_update' => false, 'incident_update' => false, 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', 'default_resolved_incident_message' => 'The service %service_name% is back to normal']]; // Dump configuration $content = $this->configurationDumper->dumpConfiguration($configuration); $this->filesystem->dumpFile($this->configurationLoader->getConfigurationFilepath(), $content); $io->writeLine('<info>Creating monitor file</info>'); } else { $io->writeLine(sprintf('<info>You already have a configuration file in</info> "%s"', $this->configurationLoader->getConfigurationFilepath())); } }
/** * 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())); } }