示例#1
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     /** @var InputExtendedInterface $input */
     $configFile = $input->getOption('config-file');
     $this->configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $input);
     $databaseConfig = $this->configuration->getConfigurationValue('Database');
     $this->database = new Database($databaseConfig);
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var InputExtendedInterface $input */
     /**
      * Welcome message
      */
     // Run gerrie:create-database-Command
     $output->writeln('<info>Gerrie will check if the current setup will work as expected.</info>');
     $output->writeln('<info>Lets start!</info>');
     /**
      * Start checking
      */
     $output->writeln('');
     $output->writeln('<comment>System:</comment>');
     // Check if curl is installed
     $curlCheck = new CurlExtensionCheck();
     $this->checkProperty($output, $curlCheck);
     // Check if PDO and MySQL are installed
     $pdoCheck = new PDOMySqlExtensionCheck();
     $this->checkProperty($output, $pdoCheck);
     // Check if SSH is installed
     $sshCheck = new SSHCheck();
     $this->checkProperty($output, $sshCheck);
     $output->writeln('');
     $output->writeln('<comment>Configuration:</comment>');
     // Check if the config file exists
     $configFileCheck = new ConfigFileCheck($input->getOption('config-file'));
     $this->checkProperty($output, $configFileCheck);
     // Check if the config file is valid
     $configFile = $input->getOption('config-file');
     $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $input);
     $configurationValidationCheck = new ConfigurationValidationCheck($configuration);
     $this->checkProperty($output, $configurationValidationCheck);
     $output->writeln('');
     $output->writeln('<comment>Connection:</comment>');
     // Check database connection
     $databaseConfig = $configuration->getConfigurationValue('Database');
     $database = new Database($databaseConfig, false);
     $databaseConnectionCheck = new DatabaseConnectionCheck($database);
     $this->checkProperty($output, $databaseConnectionCheck);
     // TODO Refactor this. This is copy / paste from CrawlCommand
     $gerritSystems = $configuration->getConfigurationValue('Gerrit');
     $defaultSSHKeyFile = $configuration->getConfigurationValue('SSH.KeyFile');
     foreach ($gerritSystems as $name => $gerrieProject) {
         foreach ($gerrieProject as $gerritInstance) {
             // Get instance url
             // If the instance is a string, we only got a url path like scheme://user@url:port/
             if (is_string($gerritInstance)) {
                 $instanceConfig = ['Instance' => $gerritInstance, 'KeyFile' => $defaultSSHKeyFile];
                 // If the instance is an array, we get a key => value structure with an Instance key
             } elseif (is_array($gerritInstance) && isset($gerritInstance['Instance'])) {
                 $instanceConfig = ['Instance' => $gerritInstance['Instance'], 'KeyFile' => $defaultSSHKeyFile];
                 if (array_key_exists('KeyFile', $gerritInstance) === true) {
                     $instanceConfig['KeyFile'] = $gerritInstance['KeyFile'];
                 }
             } else {
                 throw new \RuntimeException('No Gerrit instance config given', 1415451921);
             }
             $dataService = DataServiceFactory::getDataService($instanceConfig);
             // Check the API (SSH / HTTP) connection
             // TODO Authentification
             $apiConnectionCheck = new APIConnectionCheck($dataService);
             $this->checkProperty($output, $apiConnectionCheck);
         }
     }
     /**
      * Message end result
      */
     if ($this->overallResult === false) {
         $this->outputFixMessage($output);
     } else {
         $this->outputEverythingIsFineAndIWantABeerMessage($output);
     }
 }
 public function testGetConfigurationByConfigFileAndCommandOptionsAndArgumentsWitDummyInstanceArgument()
 {
     $argvInputExtended = $this->getArgvInputExtendedMockObject(false, true, true);
     $configFile = $this->getFixtureConfigFilePath();
     $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);
     $this->assertInstanceOf('Gerrie\\Component\\Configuration\\Configuration', $configuration);
     $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
     $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
     $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
     $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
     $this->assertInternalType('array', $configuration->getConfigurationValue('Gerrit.Gerrie'));
     $instances = $this->getDummyInstances();
     $this->assertEquals($instances, $configuration->getConfigurationValue('Gerrit.Gerrie'));
 }