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; }
$t->is($set->hasArgument('bar'), false, '->hasArgument() returns false if an nbArgument does not exists for the given name'); // ->countRequired() $t->comment('nbArgumentSetTest - Test argument required count'); $set = new nbArgumentSet(array($requiredArgument)); $t->is($set->countRequired(), 1, '->countRequired() returns the number of required arguments'); $set->addArgument($fooArgument); $t->is($set->countRequired(), 1, '->countRequired() returns the number of required arguments'); // ->count() $t->comment('nbArgumentSetTest - Test get argument count'); $set = new nbArgumentSet(); $set->addArgument($fooArgument); $t->is($set->count(), 1, '->count() returns the number of arguments'); $set->addArgument($barArgument); $t->is($set->count(), 2, '->count() returns the number of arguments'); // ->getDefaultValues() $t->comment('nbArgumentSetTest - Test get values()'); $set = new nbArgumentSet(); $set->addArguments(array(new nbArgument('foo', nbArgument::REQUIRED), new nbArgument('foo1', nbArgument::OPTIONAL), new nbArgument('foo2', nbArgument::OPTIONAL, '', 'default'), new nbArgument('foo3', nbArgument::OPTIONAL | nbArgument::IS_ARRAY))); $t->is($set->getDefaultValues(), array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), '->getDefaultValues() returns the default values for each argument'); $set = new nbArgumentSet(); $set->addArguments(array(new nbArgument('foo4', nbArgument::OPTIONAL | nbArgument::IS_ARRAY, '', array(1, 2)))); $t->is($set->getDefaultValues(), array('foo4' => array(1, 2)), '->getDefaultValues() return the default values for each argument'); $t->comment('nbArgumentSet - Test to string'); $set = new nbArgumentSet(); $t->is((string) $set, '', '->__toString() returns ""'); $set = new nbArgumentSet(array($fooArgument)); $t->is((string) $set, ' [foo]', '->__toString() returns " [foo]"'); $set = new nbArgumentSet(array($requiredArgument, $fooArgument)); $t->is((string) $set, ' required [foo]', '->__toString() returns " required [foo]"'); $set = new nbArgumentSet(array($requiredArgument, $fooArgument, $arrayArgument)); $t->is((string) $set, ' required [foo] [array1] ... [arrayN]', '->__toString() returns " required [foo] [array1] ... [arrayN]"');