public function testDoNotRethrowParseErrorIfLenient() { $config = ApplicationConfig::create()->beginCommand('package')->enableLenientArgsParsing()->end(); $application = new ConsoleApplication($config); $command = $application->getCommand('package'); $rawArgs = new StringArgs('package --foo'); $resolvedCommand = $this->resolver->resolveCommand($rawArgs, $application, true); $args = new Args($command->getArgsFormat(), $rawArgs); $this->assertSame($command, $resolvedCommand->getCommand()); $this->assertEquals($args, $resolvedCommand->getArgs()); }
public function testCreate() { $config = ApplicationConfig::create()->setName('test-bin')->setDisplayName('Test Name')->setVersion('1.2.3')->setHelperSet($helperSet = new HelperSet())->beginCommand('command')->end(); $application = new ConsoleApplication($config); $adapter = new ApplicationAdapter($application); $this->assertSame('Test Name', $adapter->getName()); $this->assertSame('1.2.3', $adapter->getVersion()); $this->assertSame('<info>Test Name</info> version <comment>1.2.3</comment>', $adapter->getLongVersion()); $this->assertSame('<info>Test Name</info> version <comment>1.2.3</comment>', $adapter->getHelp()); $this->assertSame($helperSet, $adapter->getHelperSet()); $this->assertSame(array(), $adapter->getNamespaces()); $this->assertEquals(new ArgsFormatInputDefinition($application->getGlobalArgsFormat()), $adapter->getDefinition()); $commandAdapter = new CommandAdapter($application->getCommand('command'), $adapter); $commandAdapter->setApplication($adapter); $commandAdapter->setHelperSet($helperSet); $this->assertEquals($commandAdapter, $adapter->get('command')); }
/** * ConsoleApplication constructor. * * @param callable|ApplicationConfig $config * @param CommandBus $commandBus * @param EventBus $eventBus */ public function __construct($config, CommandBus $commandBus, EventBus $eventBus) { $this->commandBus = $commandBus; $this->eventBus = $eventBus; $this->defaultHandler = new DefaultEventHandler(); $this->commandConverter = new ConsoleArgsToCommand(); parent::__construct($this->normalizeConfig($config)); }
public function testRenderOptionCommandWithPreferredLongName() { $config = ApplicationConfig::create()->setName('test-bin')->beginCommand('command')->beginOptionCommand('add', 'a')->setDescription('Description of "add"')->setPreferLongName()->end()->end(); $application = new ConsoleApplication($config); $help = new CommandHelp($application->getCommand('command')); $help->render($this->io); $expected = <<<'EOF' USAGE test-bin command or: test-bin command --add COMMANDS --add (-a) Description of "add" EOF; $this->assertSame($expected, $this->io->fetchOutput()); }
public function testUseConfiguredStyleSet() { $styleSet = new StyleSet(); $styleSet->add(Style::tag('custom')); $this->config->setStyleSet($styleSet)->beginCommand('command')->setHandler(new CallbackHandler(function (Args $args, IO $io) { PHPUnit_Framework_Assert::assertSame('text', $io->removeFormat('<custom>text</custom>')); return 123; }))->end(); $application = new ConsoleApplication($this->config); $args = new StringArgs('command'); $inputStream = new StringInputStream(); $outputStream = new BufferedOutputStream(); $errorStream = new BufferedOutputStream(); $status = $application->run($args, $inputStream, $outputStream, $errorStream); $this->assertSame(123, $status); }
/** * @expectedException \Webmozart\Console\Api\Command\NoSuchCommandException */ public function testThrowExceptionIfCatchingNotActive() { $this->config->setCatchExceptions(false)->beginCommand('list')->setHandler(new CallbackHandler(function () { throw NoSuchCommandException::forCommandName('foobar', 123); }))->end(); $args = new StringArgs('list'); $input = new StringInputStream(); $output = new BufferedOutputStream(); $errorOutput = new BufferedOutputStream(); $application = new ConsoleApplication($this->config); $application->run($args, $input, $output, $errorOutput); }
<?php use Webmozart\Console\Config\DefaultApplicationConfig; use Webmozart\Console\ConsoleApplication; use Webmozart\Console\Handler\CallbackHandler; require_once __DIR__ . '/../../vendor/autoload.php'; $config = DefaultApplicationConfig::create()->setTerminateAfterRun(true)->editCommand('help')->setHandler(new CallbackHandler(function () { return 123; }))->end(); $application = new ConsoleApplication($config); $application->run(); // Should not be executed exit(234);