$command->setDescription('command description'); $t->is($command->getDescription(), 'command description', '->getDescription() is "command description"'); $t->comment('nbCommandTest - Test aliases'); $command = new DummyCommand("foo"); $t->ok(!$command->hasAliases(), '->hasAliases() returns false'); $t->ok(!$command->hasAlias('f'), '->hasAlias() returns false'); $command->setAlias('f'); $t->ok($command->hasAliases(), '->hasAliases() returns true'); $t->ok($command->hasAlias('f'), '->hasAlias() returns true'); $command = new DummyCommand("foo"); $command->setAliases(array('f', 'fo')); $t->ok($command->hasAliases(), '->setAliases() sets 2 alias'); $t->ok($command->hasAlias('f'), '->hasAlias() returns true'); $t->ok($command->hasAlias('fo'), '->hasAlias() returns true'); try { $command->setAlias('f'); $t->fail('->setAlias() throws an InvalidArgumentException if command alias already defined'); } catch (InvalidArgumentException $e) { $t->pass('->setAlias() throws an InvalidArgumentException if command alias already defined'); } $t->comment('nbCommandTest - Test command without arguments'); try { $command = new DummyNoArgsCommand(); $t->pass('->new doesn\'t throws exception'); } catch (Exception $e) { $t->fail('->new doesn\'t throws exception'); } /* $t->comment('nbCommandTest - Test options defined in nbConfig'); $optionOptional = new nbOption('foo', '', nbOption::PARAMETER_OPTIONAL, '', 'defaultvalue'); $optionRequired = new nbOption('bar', '', nbOption::PARAMETER_REQUIRED, '');
$t->is($application->getVersion(), 'UNDEFINED', '->getVersion() is "UNDEFINED"'); $t->is($application->hasArguments(), true, '__construct() returns an application with arguments'); $t->is($application->hasOptions(), true, '__construct() returns an application with options'); $t->is($application->hasCommands(), false, '__construct() returns an application without commands'); $application = new DummyApplication($serviceContainer, array($fooArgument)); $t->is($application->hasArguments(), true, '__construct() returns an application with an argument'); $t->is($application->getArguments()->count(), 2, '__construct() returns an application with 2 arguments'); $application = new DummyApplication($serviceContainer, array(), array($barOption)); $t->is($application->hasOptions(), true, '__construct() returns an application with an option'); $t->is($application->getOptions()->count(), 5, '__construct() returns an application with 5 options'); $t->comment('nbApplicationTest - Test run'); $foo = new DummyCommand('foo', null, new nbOptionSet(array(new nbOption('first', 'f')))); $bar = new DummyCommand('bar', new nbArgumentSet(array(new nbArgument('first', nbArgument::REQUIRED)))); $bas = new DummyCommand('bas', null, new nbOptionSet(array(new nbOption('first', 'f')))); $fas = new DummyCommand('fas'); $fas->setAlias('fou'); $application = new DummyApplication($serviceContainer); //$application->setCommands(new nbCommandSet(array($foo, $bar, $bas, $fas))); $serviceContainer->commandLoader->addCommands(array($foo, $bar, $bas, $fas)); $application->run('foo'); $t->ok($foo->hasExecuted(), '->run() executes command "foo"'); $application->run('bar test'); $t->ok($bar->hasExecuted(), '->run() executes command "bar test"'); $t->is($bar->getArgument('first'), 'test', '->run() executes command "bar test"'); $application->run('bas -f'); $t->ok($bas->hasExecuted(), '->run() executes command "bas -f"'); $t->is($bas->getOption('first'), true, '->run() executes command "bas -f"'); $application->run('fou'); $t->ok($fas->hasExecuted(), '->run() executes command "fas" with alias "fou"'); $t->comment('ApplicationTest - Test VerifyOption'); $application = new DummyApplication($serviceContainer, array(), array(new nbOption('option1')));