<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(40); $fooArgument = new nbArgument('foo'); $barOption = new nbOption('bar'); $command1 = new DummyCommand("foo"); $command2 = new DummyCommand("ns:bar", new nbArgumentSet(array($fooArgument))); $command3 = new DummyCommand("ns2:bas", null, new nbOptionSet(array($barOption))); $t->comment('nbCommandTest - Test constructor'); try { new DummyCommand(''); $t->fail('command name can\'t be empty'); } catch (InvalidArgumentException $e) { $t->pass('command name can\'t be empty'); } try { new DummyCommand('ns:'); $t->fail('command name can\'t be empty'); } catch (InvalidArgumentException $e) { $t->pass('command name can\'t be empty'); } $command = new DummyCommand('foo'); $t->is($command->getArguments()->count(), 0, '->__construct() returns a command with no arguments'); $t->is($command->getOptions()->count(), 0, '->__construct() returns a command with no options'); $t->comment('nbCommandTest - Test name'); $t->is($command1->getName(), "foo", '->getName() returns a command with name "foo"'); $t->is($command2->getName(), "bar", '->getName() returns a command with name "bar"'); $t->comment('nbCommandTest - Test namespace'); $t->is($command1->getNamespace(), "", '->getNamespace() returns an empty namespace'); $t->is($command2->getNamespace(), "ns", '->getNamespace() returns a namespace "ns"');
$application = new DummyBeeApplication($serviceContainer); $foo = new DummyCommand('foo', null, new nbOptionSet(array(new nbOption('first', 'f')))); $serviceContainer->commandLoader->reset(); $serviceContainer->commandLoader->addCommands(array($foo)); $application->run('--config=nb_path1=cmdvalue1 --config=nb_path2=cmdvalue2 foo'); $t->is(nbConfig::get('nb_path1'), 'cmdvalue1', 'option "--config" creates multiple nbConfig properties'); $t->is(nbConfig::get('nb_path2'), 'cmdvalue2', 'option "--config" creates multiple nbConfig properties'); $t->ok($foo->hasExecuted(), 'command "foo" has executed'); $t->comment('nbApplicationTest - Test --enable-plugin option'); $serviceContainer->pluginLoader->addDir(nbConfig::get('nb_test_plugins_dir')); $application = new DummyBeeApplication($serviceContainer); $application->run('--enable-plugin=FirstPlugin first'); $t->ok(class_exists('DummyCommand'), 'option --enable-plugin enables a single plugin'); $t->comment('nbApplicationTest - Can execute with verbose option'); $application = new DummyBeeApplication($serviceContainer); $foo = new DummyCommand('foo'); $serviceContainer->commandLoader->reset(); $serviceContainer->commandLoader->addCommands(array($foo)); $application->run('-v foo'); $t->is($foo->getLog(), 'Log message', 'command "foo" has logged correctly'); $application->run('foo'); $t->is($foo->getLog(), 'Log message', 'command "foo" has no log'); $t->comment('nbApplicationTest - Test load dummy configuration'); $dummy = new DummyCommandWithConfiguration(); $serviceContainer->commandLoader->reset(); $serviceContainer->commandLoader->addCommands(array($dummy)); $application->run('dummyconfig'); $t->is($dummy->getConfig('app_field0'), 'value1/value1', 'command has replaced tokens correctly'); $t->is($dummy->getConfig('app_field1'), 'value1', 'command has loaded configuration correctly'); $t->is($dummy->getConfig('app_field2'), 'value1', 'command has replaced tokens correctly'); $t->is($dummy->getConfig('app_field3'), 'value1/value1/value1', 'command has replaced tokens correctly');
public function testDefaultCommandArgsIsEmptyList() { // setup $obj = new DummyCommand(); // do the test $definedArgs = $obj->getCommandArgs(); // test the results $this->assertTrue(is_array($definedArgs)); $this->assertEquals(0, count($definedArgs)); }
<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(); $fooArgument = new nbArgument('foo'); $barOption = new nbOption('bar'); $command1 = new DummyCommand("ns2:bas", new nbArgumentSet(array($fooArgument)), new nbOptionSet(array($barOption))); $command1->setBriefDescription('brief description'); $aliasCommand = new nbAliasCommand('ns:alias', $command1); $t->comment('nbAliasCommandTest - Test fullname'); $t->is($aliasCommand->getFullname(), "ns:alias", '->getFullName() returns a name without ":"'); $t->comment('nbAliasCommandTest - Test arguments'); $t->is($aliasCommand->getArguments()->count(), 1, '->getArguments() returns 1 argument'); $t->is($aliasCommand->getOptions()->count(), 2, '->getOptions() returns 1 options'); $t->comment('nbAliasCommandTest - Test description'); $t->is($aliasCommand->getBriefDescription(), "brief description", '->getBriefDescription() returns a the contained command description'); $t->comment('nbAliasCommandTest - Test run (success)'); $t->ok($aliasCommand->run(new nbCommandLineParser(), '')); $t->ok($command1->hasExecuted()); $t->comment('nbAliasCommandTest - Test run (failure)'); $command1->failOnExecute(); $t->ok(!$aliasCommand->run(new nbCommandLineParser(), '')); $t->ok($command1->hasExecuted());
$t->pass('->getByShortcut() throw a RangeException for shortcut "u"'); } try { $set->getCommand('b'); $t->fail('->getByShortcut() throw a RangeException for shortcut "b" because ambiguous'); } catch (LogicException $e) { $t->pass('->getByShortcut() throw a RangeException for shortcut "b" because ambiguous'); } try { $set->getCommand('ns:ba'); $t->fail('->getByShortcut() throw a RangeException for shortcut "ns:ba" because ambiguous'); } catch (LogicException $e) { $t->pass('->getByShortcut() throw a RangeException for shortcut "ns:ba" because ambiguous'); } $t->comment('nbCommandSetTest - Test aliases'); $command = new DummyCommand("foo"); $command->setAliases(array('b', 'bar')); $set = new nbCommandSet(array($command)); $t->ok($set->hasCommand('b'), '->hasCommand() returns true for alias "b"'); $t->ok($set->hasCommand('bar'), '->hasCommand() returns true for alias "bar"'); $t->isa_ok($set->getCommand('b'), 'DummyCommand', '->getCommand() returns a command for alias "b"'); $t->isa_ok($set->getCommand('bar'), 'DummyCommand', '->getCommand() returns a command for alias "bar"'); $t->comment('nbCommandSetTest - Test command with same name an different namespace'); $command1 = new DummyCommand("foo:cmd"); $command2 = new DummyCommand("bar:cmd"); try { new nbCommandSet(array($command1, $command2)); $t->pass('->new doesn\'t throws exception'); } catch (Exception $e) { $t->fail('->new doesn\'t throws exception'); }
<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(); $fooArgument = new nbArgument('foo'); $barOption = new nbOption('bar'); $command1 = new DummyCommand("foo"); $command2 = new DummyCommand("ns:bar", new nbArgumentSet(array($fooArgument))); $command3 = new DummyCommand("ns2:bas", null, new nbOptionSet(array($barOption))); class TestChainCommand extends nbChainCommand { protected function configure() { $this->setName('dummy:test')->setBriefDescription('TestChainCommand')->setDescription(''); } public function setCommandChain(array $commands) { $this->commands = $commands; } } $chainCommand = new TestChainCommand(); $t->comment('nbChainCommandTest - Test empty chain'); $t->ok($chainCommand->run(new nbCommandLineParser(array(), array()), '')); $t->comment('nbChainCommandTest - Test one command in chain'); $chainCommand->setCommandChain(array($command1)); $t->ok($chainCommand->run(new nbCommandLineParser(array(), array()), '')); $t->ok($command1->hasExecuted()); $t->comment('nbChainCommandTest - Test two commands in chain'); $chainCommand->setCommandChain(array($command1, $command2)); $t->ok($chainCommand->run(new nbCommandLineParser(array(), array()), '')); $t->ok($command1->hasExecuted());