/** * Test describe method. * * @return void * * @since 1.0 */ public function testDescribe() { $compare = '<comment>Test Console</comment> - version: 1.2.3 ------------------------------------------------------------ [<comment>foo</comment> Help] foo desc Usage: foo command option Options: <info>-q / --quiet</info> q desc Available commands: <info>aaa </info>No description <info>bar </info>Bar command desc <info>yoo </info>No description foo help'; $console = new Console(null, null, new TestStdout()); $console->setName('Test Console')->setVersion('1.2.3')->setDescription('test desc'); $command = new FooCommand(); $command->setApplication($console)->setDescription('foo desc')->setUsage('foo command option')->setHelp('foo help')->addCommand('bar', 'Bar command desc')->addCommand('yoo')->addOption(array('q', 'quiet'), 'default', 'q desc'); $result = $this->instance->describe($command); $this->assertEquals(str_replace(PHP_EOL, "\n", trim($compare)), str_replace(PHP_EOL, "\n", trim($result))); }
/** * Test set code. * * @return void * * @since 1.0 */ public function testsetHandler() { $this->instance->setHandler(function ($command) { return 221; }); $this->assertInstanceOf('\\Closure', $this->instance->getRootCommand()->getHandler(), 'Code need to be a closure.'); $this->assertEquals(221, $this->instance->getRootCommand()->setInput(new Input\Cli())->execute()); }
/** * Class constructor. * * @param Input\Cli $input An optional argument to provide dependency injection for the application's * input object. If the argument is a InputCli object that object will become * the application's input object, otherwise a default input object is created. * * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * * @param CliOutput $output The output handler. */ public function __construct(Input\Cli $input = null, Registry $config = null, CliOutput $output = null) { $this->loadDispatcher(); $input = $input ?: $this->getContainer()->get('input'); // Make Windows no ANSI color if (defined('PHP_WINDOWS_VERSION_BUILD')) { $input->set('no-ansi', true); } \JFactory::$application = $this; parent::__construct($input, $config, $output); $this->rootCommand->setHelp(<<<HELP Welcome to Windwalker Console. HELP ); $descriptorHelper = $this->rootCommand->getChild('help')->getDescriptor(); $descriptorHelper->setOptionDescriptor(new OptionDescriptor())->setCommandDescriptor(new CommandDescriptor()); $this->loadFirstlevelCommands(); }