Ejemplo n.º 1
0
 public function testMergeApplicationDefinition()
 {
     $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(new InputArgument('bar'), new InputOption('foo'))));
     $command->mergeApplicationDefinition();
     $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
     $this->assertTrue($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
     $this->assertTrue($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options');
     $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');
     $command->mergeApplicationDefinition();
     $this->assertEquals(3, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
     $command = new \TestCommand();
     $command->mergeApplicationDefinition();
 }
Ejemplo n.º 2
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');
 }
Ejemplo n.º 3
0
$ret = $command->setAliases(array('name1'));
$t->is($ret, $command, '->setAliases() implements a fluent interface');
$t->is($command->getAliases(), array('name1'), '->setAliases() sets the aliases');

// ->getSynopsis()
$t->diag('->getSynopsis()');
$t->is($command->getSynopsis(), '%s foobar:bar [--foo] [foo]', '->getSynopsis() returns the synopsis');

// ->mergeApplicationDefinition()
$t->diag('->mergeApplicationDefinition()');
$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(new InputArgument('bar'), new InputOption('foo'))));
$command->mergeApplicationDefinition();
$t->ok($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$t->ok($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
$t->ok($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options');
$t->ok($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');

$command->mergeApplicationDefinition();
$t->is($command->getDefinition()->getArgumentCount(), 3, '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');

$command = new TestCommand();
$command->mergeApplicationDefinition();
$t->pass('->mergeApplicationDefinition() does nothing if application is not set');

// ->run()
$t->diag('->run()');