/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Platformsh\Cli\Helper\QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $options = $this->form->resolveOptions($input, $output, $questionHelper);
     $estimate = $this->getEstimate($options['plan'], $options['storage'], $options['environments']);
     if (!$estimate) {
         $costConfirm = "Failed to estimate project cost";
     } else {
         $costConfirm = "The estimated monthly cost of this project is: <comment>{$estimate['total']}</comment>";
     }
     $costConfirm .= "\n\nAre you sure you want to continue?";
     if (!$questionHelper->confirm($costConfirm)) {
         return 1;
     }
     $subscription = $this->api()->getClient()->createSubscription($options['region'], $options['plan'], $options['title'], $options['storage'] * 1024, $options['environments']);
     $this->api()->clearProjectsCache();
     $this->stdErr->writeln(sprintf('Your %s project has been requested (subscription ID: <comment>%s</comment>)', self::$config->get('service.name'), $subscription->id));
     $this->stdErr->writeln(sprintf("\nThe %s Bot is activating your project\n", self::$config->get('service.name')));
     $bot = new Bot($this->stdErr);
     $start = time();
     while ($subscription->isPending() && time() - $start < 300) {
         $bot->render();
         if (!isset($lastCheck) || time() - $lastCheck >= 2) {
             try {
                 $subscription->refresh(['timeout' => 5, 'exceptions' => false]);
                 $lastCheck = time();
             } catch (ConnectException $e) {
                 if (strpos($e->getMessage(), 'timed out') !== false) {
                     $this->stdErr->writeln('<warning>' . $e->getMessage() . '</warning>');
                 } else {
                     throw $e;
                 }
             }
         }
     }
     $this->stdErr->writeln("");
     if (!$subscription->isActive()) {
         $this->stdErr->writeln("<error>The project failed to activate</error>");
         return 1;
     }
     $this->stdErr->writeln("The project is now ready!");
     $this->stdErr->writeln("  Region: <info>{$subscription->project_region}</info>");
     $this->stdErr->writeln("  Project ID: <info>{$subscription->project_id}</info>");
     $this->stdErr->writeln("  Project title: <info>{$subscription->project_title}</info>");
     $this->stdErr->writeln("  URL: <info>{$subscription->project_ui}</info>");
     return 0;
 }
Example #2
0
 public function testNormalizedInput()
 {
     $helper = $this->getQuestionHelper();
     $definition = new InputDefinition();
     $this->form->configureInputDefinition($definition);
     $output = new NullOutput();
     $input = new ArrayInput(['--test' => $this->validString, '--mail' => $this->validMail, '--to-upper' => 'testString'], $definition);
     $input->setInteractive(false);
     $result = $this->form->resolveOptions($input, $output, $helper);
     $validResult = $this->validResult;
     $validResult['to_upper'] = 'TESTSTRING';
     $this->assertEquals($validResult, $result, 'Input has been normalized');
 }
Example #3
0
 public function testCustomValidator()
 {
     $helper = $this->getQuestionHelper();
     $definition = new InputDefinition();
     $this->form->addField(new Field('Test field', ['optionName' => 'custom-validated', 'validator' => function ($value) {
         return $value === 'valid' ? true : 'Not valid';
     }]), 'custom_validated');
     $this->form->configureInputDefinition($definition);
     $output = new NullOutput();
     $input = new ArrayInput(['--test' => $this->validString, '--mail' => $this->validMail, '--custom-validated' => 'valid'], $definition);
     $input->setInteractive(false);
     $result = $this->form->resolveOptions($input, $output, $helper);
     $validResult = $this->validResult + ['custom_validated' => 'valid'];
     $this->assertEquals($validResult, $result);
     $input = new ArrayInput(['--test' => $this->validString, '--mail' => $this->validMail, '--custom-validated' => 'not valid'], $definition);
     $input->setInteractive(false);
     $this->setExpectedException('\\Platformsh\\ConsoleForm\\Exception\\InvalidValueException', 'Not valid');
     $this->form->resolveOptions($input, $output, $helper);
 }