/** * 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; }
$t->diag('->getHelp()'); $argument = new sfCommandArgument('foo', null, 'Some help'); $t->is($argument->getHelp(), 'Some help', '->getHelp() return the message help'); // ->getDefault() $t->diag('->getDefault()'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL, '', 'default'); $t->is($argument->getDefault(), 'default', '->getDefault() return the default value'); // ->setDefault() $t->diag('->setDefault()'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL, '', 'default'); $argument->setDefault(null); $t->ok(null === $argument->getDefault(), '->setDefault() can reset the default value by passing null'); $argument->setDefault('another'); $t->is($argument->getDefault(), 'another', '->setDefault() changes the default value'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY); $argument->setDefault(array(1, 2)); $t->is($argument->getDefault(), array(1, 2), '->setDefault() changes the default value'); try { $argument = new sfCommandArgument('foo', sfCommandArgument::REQUIRED); $argument->setDefault('default'); $t->fail('->setDefault() throws an sfCommandException if you give a default value for a required argument'); } catch (sfCommandException $e) { $t->pass('->setDefault() throws an sfCommandException if you give a default value for a required argument'); } try { $argument = new sfCommandArgument('foo', sfCommandArgument::IS_ARRAY); $argument->setDefault('default'); $t->fail('->setDefault() throws an sfCommandException if you give a default value which is not an array for a IS_ARRAY option'); } catch (sfCommandException $e) { $t->pass('->setDefault() throws an sfCommandException if you give a default value which is not an array for a IS_ARRAY option'); }