} try { $input->getArgument('foo'); $t->fail('->getArgument() throws a \\InvalidArgumentException if the argument does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getArgument() throws a \\InvalidArgumentException if the argument does not exist'); } // ->validate() $t->diag('->validate()'); $input = new ArrayInput(array()); $input->bind(new Definition(array(new Argument('name', Argument::REQUIRED)))); try { $input->validate(); $t->fail('->validate() throws a \\RuntimeException if not enough arguments are given'); } catch (\RuntimeException $e) { $t->pass('->validate() throws a \\RuntimeException if not enough arguments are given'); } $input = new ArrayInput(array('name' => 'foo')); $input->bind(new Definition(array(new Argument('name', Argument::REQUIRED)))); try { $input->validate(); $t->pass('->validate() does not throw a \\RuntimeException if enough arguments are given'); } catch (\RuntimeException $e) { $t->fail('->validate() does not throw a \\RuntimeException if enough arguments are given'); } // ->setInteractive() ->isInteractive() $t->diag('->setInteractive() ->isInteractive()'); $input = new ArrayInput(array()); $t->ok($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not'); $input->setInteractive(false); $t->ok(!$input->isInteractive(), '->setInteractive() changes the interactive flag');
/** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ public function doRun(InputInterface $input, OutputInterface $output) { $name = $input->getFirstArgument('command'); if (true === $input->hasParameterOption(array('--color', '-c'))) { $output->setDecorated(true); } if (true === $input->hasParameterOption(array('--help', '-H'))) { if (!$name) { $name = 'help'; $input = new ArrayInput(array('command' => 'help')); } else { $this->wantHelps = true; } } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(Output::VERBOSITY_QUIET); } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) { $output->setVerbosity(Output::VERBOSITY_VERBOSE); } if (true === $input->hasParameterOption(array('--version', '-V'))) { $output->write($this->getLongVersion()); return 0; } if (!$name) { $name = 'list'; $input = new ArrayInput(array('command' => 'list')); } // the command name MUST be the first element of the input $command = $this->findCommand($name); $this->runningCommand = $command; $statusCode = $command->run($input, $output); $this->runningCommand = null; return is_numeric($statusCode) ? $statusCode : 0; }