示例#1
0
 public static function formatArguments(nbArgumentSet $argumentSet, $max)
 {
     $arguments = $argumentSet->getArguments();
     if (count($arguments) == 0) {
         return '';
     }
     $res = "\n";
     $res .= self::format("Arguments:", nbLogger::COMMENT) . "\n";
     foreach ($arguments as $argument) {
         $res .= self::format(sprintf(" %-{$max}s ", $argument->getName()), nbLogger::INFO);
         $res .= $argument->getDescription();
         if ($argument->isRequired()) {
             $res .= self::format(' (required)', nbLogger::COMMENT);
         } else {
             if (null !== $argument->getValue() && !$argument->isArray()) {
                 $res .= self::format(' (default: ' . $argument->getValue() . ')', nbLogger::COMMENT);
             }
         }
         $res .= "\n";
     }
     return $res;
 }
示例#2
0
$set = new nbArgumentSet(array($fooArgument));
$t->is($set->count(), 1, '->__construct() has 1 argument');
$t->is($set->countRequired(), 0, '->__contruct() has no required arguments');
$t->is($set->hasArgument('foo'), true, '->__construct() built a set with argument "foo"');
// ->addArguments()
$t->comment('nbArgumentSetTest - Test add arguments array');
$set = new nbArgumentSet();
$set->addArguments(array($fooArgument, $barArgument));
$t->is($set->getArguments(), array('foo' => $fooArgument, 'bar' => $barArgument), '->addArguments() added an array of arguments');
$set->addArguments(array($basArgument));
$t->is($set->getArguments(), array('foo' => $fooArgument, 'bar' => $barArgument, 'bas' => $basArgument), '->addArguments() does not clear previous arguments');
// ->addArgument()
$t->comment('nbArgumentSetTest - Test add argument');
$set = new nbArgumentSet();
$set->addArgument($fooArgument);
$t->is($set->getArguments(), array('foo' => $fooArgument), '->addArgument() added argument "foo"');
try {
    $set->addArgument($fooArgument);
    $t->fail('->addArgument() throws an InvalidArgumentException if an argument with the same name is added');
} catch (InvalidArgumentException $e) {
    $t->pass('->addArgument() throws an InvalidArgumentException if an argument with the same name is added');
}
$set = new nbArgumentSet(array($arrayArgument));
try {
    $set->addArgument($fooArgument);
    $t->fail('->addArgument() throws an InvalidArgumentException if there is an array parameter already registered');
} catch (InvalidArgumentException $e) {
    $t->pass('->addArgument() throws an InvalidArgumentException if there is an array parameter already registered');
}
// cannot add a required argument after an optional one
$set = new nbArgumentSet(array($fooArgument));