/**
  * Overridden so that the application doesn't expect the command
  * name to be the first argument.
  */
 public function getDefinition()
 {
     $inputDefinition = parent::getDefinition();
     // clear out the normal first argument, which is the command name
     $inputDefinition->setArguments();
     return $inputDefinition;
 }
Example #2
0
 public function testSettingCustomInputDefinitionOverwritesDefaultValues()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->setDefinition(new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.'))));
     $inputDefinition = $application->getDefinition();
     // check whether the default arguments and options are not returned any more
     $this->assertFalse($inputDefinition->hasArgument('command'));
     $this->assertFalse($inputDefinition->hasOption('help'));
     $this->assertFalse($inputDefinition->hasOption('quiet'));
     $this->assertFalse($inputDefinition->hasOption('verbose'));
     $this->assertFalse($inputDefinition->hasOption('version'));
     $this->assertFalse($inputDefinition->hasOption('ansi'));
     $this->assertFalse($inputDefinition->hasOption('no-ansi'));
     $this->assertFalse($inputDefinition->hasOption('no-interaction'));
     $this->assertTrue($inputDefinition->hasOption('custom'));
 }
Example #3
0
 public function testMergeApplicationDefinitionWithoutArgsThenWithArgsAddsArgs()
 {
     $application1 = new Application();
     $application1->getDefinition()->addArguments(array(new InputArgument('foo')));
     $application1->getDefinition()->addOptions(array(new InputOption('bar')));
     $command = new \TestCommand();
     $command->setApplication($application1);
     $command->setDefinition($definition = new InputDefinition(array()));
     $r = new \ReflectionObject($command);
     $m = $r->getMethod('mergeApplicationDefinition');
     $m->setAccessible(true);
     $m->invoke($command, false);
     $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition(false) merges the application and the commmand options');
     $this->assertFalse($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(false) does not merge the application arguments');
     $m->invoke($command, true);
     $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(true) merges the application arguments and the command arguments');
     $m->invoke($command);
     $this->assertEquals(2, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments');
 }