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
$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()');
$command = new TestCommand();
$command->setApplication($application);
$tester = new CommandTester($command);
try
{
  $tester->execute(array('--bar' => true));
  $t->fail('->run() throws a \RuntimeException when the input does not validate the current InputDefinition');
}
catch (\RuntimeException $e)
{
  $t->pass('->run() throws a \RuntimeException when the input does not validate the current InputDefinition');