예제 #1
0
파일: nbArgumentSet.php 프로젝트: nubee/bee
 /**
  * Add a nbArgument objects.
  *
  * @param nbArgument $argument A nbArgument object
  */
 public function addArgument(nbArgument $argument)
 {
     if (isset($this->arguments[$argument->getName()])) {
         throw new InvalidArgumentException(sprintf('[nbArgumentSet::addArgument] An argument with name "%s" already exist.', $argument->getName()));
     }
     if ($this->hasAnArrayArgument) {
         throw new InvalidArgumentException('[nbArgumentSet::addArgument] Cannot add an argument after an array argument.');
     }
     if ($argument->isRequired() && $this->hasAnOptionalArgument) {
         throw new InvalidArgumentException('[nbArgumentSet::addArgument] Cannot add a required argument after an optional one.');
     }
     if ($argument->isArray()) {
         $this->hasAnArrayArgument = true;
     }
     if ($argument->isRequired()) {
         ++$this->requiredCount;
     } else {
         $this->hasAnOptionalArgument = true;
     }
     $this->arguments[$argument->getName()] = $argument;
 }
예제 #2
0
}
$t->comment('nbArgumentTest - Test required argument');
$argument = new nbArgument('command', nbArgument::REQUIRED, 'The command to execute');
$t->is($argument->getName(), 'command', '->getName() argument name is "command"');
$t->is($argument->isRequired(), true, '->isRequired() argument is required');
try {
    $argument->getValue();
    $t->fail('->getValue() throws if required argument has not been set');
} catch (LogicException $e) {
    $t->pass('->getValue() throws if required argument has not been set');
}
$argument->setValue("list");
$t->is($argument->getValue(), "list", "->getValue() returns 'list'");
$t->comment('nbArgumentTest - Test optional argument');
$argument = new nbArgument('command', nbArgument::OPTIONAL, 'The command to execute', 'description');
$t->is($argument->getName(), 'command', '->getName() argument name is "command"');
$t->is($argument->isRequired(), false, '->isRequired() argument is not required');
//$t->is($argument->getValue(), "description", "argument value is 'description'");
//$t->is($argument->toString(), "[command]", "argument toString is '[command]'");
$t->comment('nbArgumentTest - Test ctor');
try {
    $argument = new nbArgument('foo', 'ANOTHER_ONE');
    $t->fail('->__construct() throws an Exception if the mode is not valid');
} catch (Exception $e) {
    $t->pass('->__construct() throws an Exception if the mode is not valid');
}
$t->comment('nbArgumentTest - Test if an argument is an array');
$argument = new nbArgument('foo', nbArgument::IS_ARRAY);
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');
$argument = new nbArgument('foo', nbArgument::OPTIONAL | nbArgument::IS_ARRAY);
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');