コード例 #1
0
ファイル: InputTest.php プロジェクト: yamildiego/JY
 public function testArguments()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
     $input->setArgument('name', 'bar');
     $this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
     $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
     $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
     $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
     try {
         $input->setArgument('foo', 'bar');
         $this->fail('->setArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
     try {
         $input->getArgument('foo');
         $this->fail('->getArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
 }
コード例 #2
0
ファイル: UpdateCommand.php プロジェクト: miguelibero/meinhof
 protected function runSetup(InputInterface $input, OutputInterface $output)
 {
     $command = new SetupCommand();
     if ($helper = $this->getHelperSet()) {
         $command->setHelperSet($helper);
     }
     $input = new ArrayInput(array('dir' => $input->getArgument('dir'), '--update' => false));
     $command->run($input, $output);
 }
コード例 #3
0
 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage The "foo" argument does not exist.
  */
 public function testGetInvalidArgument()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
     $input->getArgument('foo');
 }
コード例 #4
0
 /**
  * Display the help output for the intended command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 protected function displayHelpOutputForCommand($input, $output)
 {
     if (!$input->hasParameterOption('--help', true) && $input->hasArgument('command')) {
         $input = new ArrayInput(['command' => $input->getArgument('command'), '--help']);
         $this->handle($input, $output);
     }
 }