/** * Add a sfCommandArgument objects. * * @param sfCommandArgument $argument A sfCommandArgument object */ public function addArgument(sfCommandArgument $argument) { if (isset($this->arguments[$argument->getName()])) { throw new sfCommandException(sprintf('An argument with name "%s" already exist.', $argument->getName())); } if ($this->hasAnArrayArgument) { throw new sfCommandException('Cannot add an argument after an array argument.'); } if ($argument->isRequired() && $this->hasOptional) { throw new sfCommandException('Cannot add a required argument after an optional one.'); } if ($argument->isArray()) { $this->hasAnArrayArgument = true; } if ($argument->isRequired()) { ++$this->requiredCount; } else { $this->hasOptional = true; } $this->arguments[$argument->getName()] = $argument; }
*/ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(16); // __construct() $t->diag('__construct()'); $argument = new sfCommandArgument('foo'); $t->is($argument->getName(), 'foo', '__construct() takes a name as its first argument'); // mode argument $argument = new sfCommandArgument('foo'); $t->is($argument->isRequired(), false, '__construct() gives a "sfCommandArgument::OPTIONAL" mode by default'); $argument = new sfCommandArgument('foo', null); $t->is($argument->isRequired(), false, '__construct() can take "sfCommandArgument::OPTIONAL" as its mode'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL); $t->is($argument->isRequired(), false, '__construct() can take "sfCommandArgument::PARAMETER_OPTIONAL" as its mode'); $argument = new sfCommandArgument('foo', sfCommandArgument::REQUIRED); $t->is($argument->isRequired(), true, '__construct() can take "sfCommandArgument::PARAMETER_REQUIRED" as its mode'); try { $argument = new sfCommandArgument('foo', 'ANOTHER_ONE'); $t->fail('__construct() throws an sfCommandException if the mode is not valid'); } catch (sfCommandException $e) { $t->pass('__construct() throws an sfCommandException if the mode is not valid'); } // ->isArray() $t->diag('->isArray()'); $argument = new sfCommandArgument('foo', sfCommandArgument::IS_ARRAY); $t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY); $t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL); $t->ok(!$argument->isArray(), '->isArray() returns false if the argument can not be an array'); // ->getHelp()