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'); }
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); }
/** * {@inheritdoc} */ protected function configure() { $this->setName('project:create')->setAliases(['create'])->setDescription('Create a new project'); $this->form = Form::fromArray($this->getFields()); $this->form->configureInputDefinition($this->getDefinition()); }