コード例 #1
0
ファイル: Application.php プロジェクト: vjousse/symfony
 /**
  * Adds a command object.
  *
  * If a command with the same name already exists, it will be overridden.
  *
  * @param Command $command A Command object
  *
  * @return Command The registered command
  */
 public function addCommand(Command $command)
 {
     $command->setApplication($this);
     $this->commands[$command->getFullName()] = $command;
     foreach ($command->getAliases() as $alias) {
         $this->aliases[$alias] = $command;
     }
     return $command;
 }
コード例 #2
0
ファイル: CommandTest.php プロジェクト: vjousse/symfony
use Symfony\Components\CLI\Output\StreamOutput;
use Symfony\Components\CLI\Tester\CommandTester;
$fixtures = __DIR__ . '/../../../../../fixtures/Symfony/Components/CLI';
$t = new LimeTest(46);
require_once $fixtures . '/TestCommand.php';
$application = new Application();
// __construct()
$t->diag('__construct()');
try {
    $command = new Command();
    $t->fail('__construct() throws a \\LogicException if the name is null');
} catch (\LogicException $e) {
    $t->pass('__construct() throws a \\LogicException if the name is null');
}
$command = new Command('foo:bar');
$t->is($command->getFullName(), 'foo:bar', '__construct() takes the command name as its first argument');
// ->setApplication()
$t->diag('->setApplication()');
$command = new TestCommand();
$command->setApplication($application);
$t->is($command->getApplication(), $application, '->setApplication() sets the current application');
// ->setDefinition()
$t->diag('->setDefinition()');
$ret = $command->setDefinition($definition = new Definition());
$t->is($ret, $command, '->setDefinition() implements a fluent interface');
$t->is($command->getDefinition(), $definition, '->setDefinition() sets the current Definition instance');
$command->setDefinition(array(new Argument('foo'), new Option('bar')));
$t->ok($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of Arguments and Options as an argument');
$t->ok($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of Arguments and Options as an argument');
$command->setDefinition(new Definition());
// ->addArgument()