Get the helper set associated with the command.
public getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet | ||
return | Symfony\Component\Console\Helper\HelperSet | The HelperSet instance associated with this command |
public static function setApplicationDocumentManager(Application $application, $dmName) { $service = null === $dmName ? 'doctrine_phpcr.odm.document_manager' : 'doctrine_phpcr.odm.' . $dmName . '_document_manager'; $documentManager = $application->getKernel()->getContainer()->get($service); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper(null, $documentManager)); }
/** * Bootstraps the application. * * This method is called after all services are registered * and should be used for "dynamic" configuration (whenever * a service must be requested). * * @param Application $app */ public function boot(Application $app) { $helperSet = new HelperSet(array('connection' => new ConnectionHelper($app['db']), 'dialog' => new DialogHelper())); if (isset($app['orm.em'])) { $helperSet->set(new EntityManagerHelper($app['orm.em']), 'em'); } $this->console->setHelperSet($helperSet); $commands = array('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\ExecuteCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\GenerateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\StatusCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand'); // @codeCoverageIgnoreStart if (true === $this->console->getHelperSet()->has('em')) { $commands[] = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\DiffCommand'; } // @codeCoverageIgnoreEnd $configuration = new Configuration($app['db'], $app['migrations.output_writer']); $configuration->setMigrationsDirectory($app['migrations.directory']); $configuration->setName($app['migrations.name']); $configuration->setMigrationsNamespace($app['migrations.namespace']); $configuration->setMigrationsTableName($app['migrations.table_name']); $configuration->registerMigrationsFromDirectory($app['migrations.directory']); foreach ($commands as $name) { /** @var AbstractCommand $command */ $command = new $name(); $command->setMigrationConfiguration($configuration); $this->console->add($command); } }
/** * Convenience method to push the helper sets of a given entity manager into the application. * * @param Application $application * @param string $emName */ public static function setApplicationEntityManager(Application $application, $emName) { /** @var $em \Doctrine\ORM\EntityManager */ $em = $application->getHelperSet()->get('container')->getContainer()->get('doctrine')->getManager(); $helperSet = $application->getHelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); }
public function testValidHelpers() { $helperSet = $this->cli->getHelperSet(); /* @var $dmHelper \Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper */ $dmHelper = $helperSet->get('dm'); $this->assertInstanceOf('\\Doctrine\\ODM\\MongoDB\\Tools\\Console\\Helper\\DocumentManagerHelper', $dmHelper); $this->assertSame($this->entityManager, $dmHelper->getDocumentManager()); }
/** * @return CommandTester */ protected function getCommandTester() { $this->application->getHelperSet()->set($this->dialog, 'dialog'); $this->application->add($this->command); $command = $this->application->find('phpci:create-admin'); $commandTester = new CommandTester($command); return $commandTester; }
/** * Create CLI instance. * * @return Application */ public static function getInstance() { $questionHelper = new QuestionHelper(); $application = new Application('CloverToHtml Command Line Interface', 'Beta 0.1.0'); $application->getHelperSet()->set(new FormatterHelper(), 'formatter'); $application->getHelperSet()->set($questionHelper, 'question'); $application->add(ConvertCommandFactory::getInstance()); return $application; }
/** * @param string $input * * @return integer */ public function run($input) { $this->input = new StringInput($input); $this->output = new StreamOutput(fopen('php://memory', 'w', false)); $inputStream = $this->getInputStream(); rewind($inputStream); $this->application->getHelperSet()->get('dialog')->setInputStream($inputStream); $this->result = $this->application->run($this->input, $this->output); }
/** * Create CLI instance. * * @return \Symfony\Component\Console\Application */ public static function getInstance() { $questionHelper = new QuestionHelper(); $application = new Application('Code Generator Command Line Interface', 'Alpha'); $application->getHelperSet()->set(new FormatterHelper(), 'formatter'); $application->getHelperSet()->set($questionHelper, 'question'); $application->add(new ConvertDirectory()); return $application; }
/** * Create CLI instance. * * @return Application */ public static function getInstance(OutputInterface $output) { $questionHelper = new QuestionHelper(); $application = new Application('PHP to Zephir Command Line Interface', 'Beta 0.2.0'); $application->getHelperSet()->set(new FormatterHelper(), 'formatter'); $application->getHelperSet()->set($questionHelper, 'question'); $application->add(ConvertFactory::getInstance($output)); return $application; }
public function testValidHelpers() { $helperSet = $this->cli->getHelperSet(); /* @var $emHelper \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper */ $emHelper = $helperSet->get('em'); $this->assertInstanceOf('Doctrine\\ORM\\Tools\\Console\\Helper\\EntityManagerHelper', $emHelper); $this->assertSame($this->entityManager, $emHelper->getEntityManager()); /* @var $dbHelper \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper */ $dbHelper = $helperSet->get('db'); $this->assertInstanceOf('Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper', $dbHelper); $this->assertSame($this->entityManager->getConnection(), $dbHelper->getConnection()); }
/** * @param Application $cli * * @return void */ public static function addCommands(Application $cli) { $cli->addCommands([new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\LatestCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand(), new Command\UpToDateCommand()]); if ($cli->getHelperSet()->has('em')) { $cli->add(new Command\DiffCommand()); } }
public static function setApplicationConnection(Application $application, $connName) { $app = $application->getApp(); $connection = $app['db']; $helperSet = $application->getHelperSet(); $helperSet->set(new ConnectionHelper($connection), 'db'); }
function it_should_wrap_getApplication_in_a_shell(Application $app, HelperSet $helperSet) { $app->getHelperSet()->willReturn($helperSet); $app->getName()->willReturn('test'); $this->setApplication($app); $shell = $this->getShell(); $shell->shouldHaveType('Symfony\\Component\\Console\\Shell'); }
/** * @param Application $application * @param mixed $default * @param array $options * @return ConfigurationHelper */ public static function initHelper(Application $application, $default = null, array $options = []) { $options = $options + ['name' => 'config', 'abbreviation' => 'c', 'description' => 'Path to the configuration file.', 'filename' => 'cli-config.php']; $helper = new static($options['name'], $options['filename']); $helper->setDefault($default); $application->getDefinition()->addOption(new InputOption($options['name'], $options['abbreviation'], InputOption::VALUE_REQUIRED, $options['description'])); $application->getHelperSet()->set($helper); return $helper; }
/** * Sets the application instance for this command. * * @param Application $application An Application instance * * @api */ public function setApplication(Application $application = null) { $this->application = $application; if ($application) { $this->setHelperSet($application->getHelperSet()); } else { $this->helperSet = null; } }
/** @Provides("Symfony\Component\Console\Application") @Singleton */ static function provideApp($name = "UNKNOWN", $version = "UNKNOWN", $helpers = [], $commands = []) { $app = new Application($name, $version); $app->addCommands($commands); $helperSet = $app->getHelperSet(); foreach ($helpers as $alias => $helper) { $helperSet->set($helper, $alias); } return $app; }
/** * Set up all required helpers and the composer library. * * @return void */ private function setUp() { $this->formatter = $this->application->getHelperSet()->get('formatter'); $this->progress = new ProgressBar($this->output); $this->progress->setFormat('%current:6d% [%bar%] %elapsed% %message%'); $this->progress->setMessage(''); $this->factory = new Factory(); $this->io = new BufferIO(); $this->composer = $this->factory->createComposer($this->io); }
/** * @param string $input * @param array $options * * @return integer */ public function run($input, array $options = array()) { if (isset($options['interactive']) && $options['interactive']) { $this->input = new InteractiveStringInput($input); } else { $this->input = new StringInput($input); $this->input->setInteractive(false); } $this->output = new StreamOutput(fopen('php://memory', 'w', false)); if (isset($options['decorated'])) { $this->output->setDecorated($options['decorated']); } if (isset($options['verbosity'])) { $this->output->setVerbosity($options['verbosity']); } $inputStream = $this->getInputStream(); rewind($inputStream); $this->application->getHelperSet()->get('dialog')->setInputStream($inputStream); return $this->application->run($this->input, $this->output); }
public function createService(ServiceLocatorInterface $serviceLocator) { $application = new Application('TestConsole', '0.1'); $application->add(new RunSqlCommand()); $application->add(new ImportCommand()); $application->add($serviceLocator->get('UserCreateCommand')); $application->add($serviceLocator->get('ListUsersCommand')); $helperSet = $application->getHelperSet(); $helperSet->set($serviceLocator->get('ServiceManagerHelper')); return $application; }
/** * Creates the application. */ protected function setUp() { $this->cwd = getcwd(); $this->dir = $this->createDir(); chdir($this->dir); $this->app = new Application(); $this->app->getHelperSet()->set(new Helper\ConfigurationHelper()); $this->app->getHelperSet()->set(new Helper\PhpSecLibHelper()); $command = $this->getCommand(); $this->name = $command->getName(); $this->app->add($command); }
protected function setApplicationConnection(Container $container, Application $app, $connName) { if (is_null($connName)) { if (!array_key_exists($connName, $container['dbs'])) { throw new Exception(sprintf('Unknown Doctrine connection "%s"', $connName)); } $db = $container['dbs'][$connName]; } else { $db = $container['db']; } $app->getHelperSet()->set(new ConnectionHelper($db), 'db'); }
public function testExecuteCurrent() { $manifest = $this->createFile(); file_put_contents($manifest, '[]'); $command = new Command('upgrade', true); $command->setManifestUri($manifest); $app = new Application('Test', '1.0.0'); $app->getHelperSet()->set(new Helper()); $app->add($command); $tester = new CommandTester($app->get('upgrade')); $tester->execute(array('command' => 'upgrade')); $this->assertRegExp('/Already up-to-date\\./', $tester->getDisplay()); }
public function testExecuteInteractiveWithQuestionHelper() { if (!class_exists('Symfony\\Component\\Console\\Helper\\QuestionHelper')) { $this->markTestSkipped('The question helper not available.'); } $application = new Application(); $helper = $this->createMock('Symfony\\Component\\Console\\Helper\\QuestionHelper', array('ask')); $helper->expects($this->at(0))->method('ask')->will($this->returnValue('user')); $application->getHelperSet()->set($helper, 'question'); $commandTester = $this->createCommandTester($this->getContainer('user'), $application); $exitCode = $commandTester->execute(array(), array('decorated' => false, 'interactive' => true)); $this->assertEquals(0, $exitCode, 'Returns 0 in case of success'); $this->assertRegExp('/User "user" has been deactivated/', $commandTester->getDisplay()); }
public function testDocumentManagerUsedCanBeSpecifiedInCommandLineArgument() { $argvBackup = $_SERVER['argv']; $documentManager = $this->getMockbuilder('Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock(); $serviceManager = $this->getMock('Zend\\ServiceManager\\ServiceManager'); $serviceManager->expects($this->once())->method('get')->with('doctrine.documentmanager.some_other_name')->will($this->returnValue($documentManager)); $application = new Application(); $event = new Event('loadCli.post', $application, array('ServiceManager' => $serviceManager)); $_SERVER['argv'][] = '--documentmanager=some_other_name'; $module = new Module(); $module->loadCli($event); $_SERVER['argv'] = $argvBackup; $this->assertSame($documentManager, $application->getHelperSet()->get('documentManager')->getDocumentManager()); }
/** * Get a job mock * * @return \PHPUnit_Framework_MockObject_MockObject|Job */ protected function getJobMock($questionCallback = null) { $application = new Application(); if ($questionCallback) { $questionHelperMock = $this->getMock('\\Symfony\\Component\\Console\\Helper\\QuestionHelper', ['ask']); $questionHelperMock->expects($this->any())->method('ask')->willReturnCallback($questionCallback); $application->getHelperSet()->set($questionHelperMock); } $console = new Console(new Config()); $console->setInput(new ArrayInput([])); $console->setOutput(new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET)); $console->setDebugOutput(new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET)); $console->setApplication($application); $job = new \Netresearch\Kite\Job($console); $job->get('composer')->invalidatePackages(); return $job; }
public function setUp() { $processMock = $this->prophesize(Process::class); $processMock->isSuccessful()->willReturn(true); $processHelper = $this->prophesize(ProcessHelper::class); $processHelper->getName()->willReturn('process'); $processHelper->setHelperSet(Argument::any())->willReturn(null); $processHelper->run(Argument::cetera())->willReturn($processMock->reveal()); $app = new Application(); $helperSet = $app->getHelperSet(); $helperSet->set($processHelper->reveal()); $app->setHelperSet($helperSet); $this->configWriter = $this->prophesize(WriterInterface::class); $command = new InstallCommand($this->configWriter->reveal()); $app->add($command); $questionHelper = $command->getHelper('question'); $questionHelper->setInputStream($this->createInputStream()); $this->commandTester = new CommandTester($command); }
public function testListCommand() { $application = new Application(); $helpers = array('configuration' => new Chash\Helpers\ConfigurationHelper()); $helperSet = $application->getHelperSet(); foreach ($helpers as $name => $helper) { $helperSet->set($helper, $name); } $application->add(new CleanConfigFilesCommand()); $command = $application->find('files:clean_config_files'); $this->assertEquals('Chash\\Command\\Files\\CleanConfigFilesCommand', get_class($command)); /* $commandTester = new CommandTester($command); $returnCode = $commandTester->execute( array( 'command' => $command->getName(), '--conf' => 'chamilo/config/configuration.php' ) );*/ // var_dump(realpath(__DIR__.'/../../Resources/configuration.php')); // $this->assertRegExp('/11/', $commandTester->getDisplay()); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->app->initialize(); $this->app->boot(); $console = new Application(); $table = $console->getHelperSet()->get('table'); $table->setHeaders(array('Name', 'Path', 'Pattern')); $table->setLayout(TableHelper::LAYOUT_DEFAULT); $controllers = $this->app['controllers']; $collection = $controllers->flush(); foreach ($collection as $name => $route) { $requirements = array(); foreach ($route->getRequirements() as $key => $requirement) { // $requirements[] = $key . ' => ' . $requirement; $requirements[] = $requirement; } $table->addRow(array($name, $route->getPath(), join(', ', $requirements))); } $routes = $this->app['routes']->all(); $maxName = 4; $maxMethod = 6; foreach ($routes as $name => $route) { $requirements = $route->getRequirements(); $method = isset($requirements['_method']) ? strtoupper(is_array($requirements['_method']) ? implode(', ', $requirements['_method']) : $requirements['_method']) : 'ANY'; if (strlen($name) > $maxName) { $maxName = strlen($name); } if (strlen($method) > $maxMethod) { $maxMethod = strlen($method); } } foreach ($routes as $name => $route) { $requirements = $route->getRequirements(); $method = isset($requirements['_method']) ? strtoupper(is_array($requirements['_method']) ? implode(', ', $requirements['_method']) : $requirements['_method']) : 'ANY'; $table->addRow(array($name, $route->getPattern(), $method)); } $table->render($output); }
public function testExecute() { $application = new Application(); $application->getHelperSet()->set(new ParameterHelper(), 'filegenParameters'); $command = new ParameterCommand(); $application->add($command); $structure = new Structure(); $structure->parameter('foo', 'foo description')->parameter('bar', 'bar description')->parameter('baz', 'baz description'); $structure->getParameterDefinition()->get('baz')->setDefaultValue('BazValue'); $command->setStructure($structure); $commandTester = new CommandTester($command); // Set the input stream $helper = $command->getHelper('question'); $helper->setInputStream($this->getInputStream("FooValue\nBarValue\n\n")); $commandTester->execute(array('command' => $command->getName())); $this->assertEquals('foo descriptionbar descriptionbaz description', $commandTester->getDisplay()); $received = $command->getReceived(); $this->assertArrayHasKey('foo', $received); $this->assertEquals('FooValue', $received['foo']); $this->assertArrayHasKey('bar', $received); $this->assertEquals('BarValue', $received['bar']); $this->assertArrayHasKey('baz', $received); $this->assertEquals('BazValue', $received['baz']); }
public function testAddingSingleHelperSetOverwritesDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->setHelperSet(new HelperSet(array(new FormatterHelper()))); $helperSet = $application->getHelperSet(); $this->assertTrue($helperSet->has('formatter')); // no other default helper set should be returned $this->assertFalse($helperSet->has('dialog')); $this->assertFalse($helperSet->has('progress')); }