/** * {@inheritdoc} */ public function ask($question, $default = NULL) { /** @var QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new ConfirmationQuestion($question, $default); return $helper->ask($this->input, $this->output, $question); }
public function testGetCommand() { $cmd = new Command('foo'); $helperset = new HelperSet(); $helperset->setCommand($cmd); $this->assertEquals($cmd, $helperset->getCommand(), '->getCommand() retrieves stored command'); }
/** * 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); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->get('entity_manager'); $helperSet = new HelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); $helperSet->set($this->getHelper('dialog'), 'dialog'); $arguments = array(); if ($input->getArgument('version')) { $arguments['version'] = $input->getArgument('version'); } if ($input->getOption('write-sql')) { $arguments['--write-sql'] = $input->getOption('write-sql'); } if ($input->getOption('dry-run')) { $arguments['--dry-run'] = $input->getOption('dry-run'); } if ($input->getOption('query-time')) { $arguments['--query-time'] = $input->getOption('query-time'); } if ($input->getOption('allow-no-migration')) { $arguments['--allow-no-migration'] = $input->getOption('allow-no-migration'); } $configDir = $this->get('config')->get('[directories][config_dir]'); $arguments['--configuration'] = $configDir . '/migrations.yml'; $command = new MigrateCommand(); $command->setHelperSet($helperSet); $returnCode = $command->run(new ArrayInput($arguments), $output); return $returnCode; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->get('entity_manager'); $helperSet = new HelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); $arguments = array(); if ($input->getArgument('version')) { $arguments['version'] = $input->getArgument('version'); } if ($input->getOption('add')) { $arguments['--add'] = $input->getOption('add'); } if ($input->getOption('delete')) { $arguments['--delete'] = $input->getOption('delete'); } if ($input->getOption('all')) { $arguments['--all'] = $input->getOption('all'); } if ($input->getOption('range-from')) { $arguments['--range-from'] = $input->getOption('range-from'); } if ($input->getOption('range-to')) { $arguments['--range-to'] = $input->getOption('range-to'); } $configDir = $this->get('config')->get('[directories][config_dir]'); $arguments['--configuration'] = $configDir . '/migrations.yml'; $command = new VersionCommand(); $command->setHelperSet($helperSet); $returnCode = $command->run(new ArrayInput($arguments), $output); return $returnCode; }
/** * @return \PhpSpec\Console\Prompter */ public function getPrompter() { if ($this->helperSet->has('question')) { return new Question($this->input, $this->output, $this->helperSet->get('question')); } return new Dialog($this->output, $this->helperSet->get('dialog')); }
/** * @param string $question * @param null $default * * @return string */ protected function ask($question, $default = null) { /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new Question($question, $default); return $helper->ask($this->input, $this->getErrorOutput(), $question); }
/** * @inheritdoc */ public function register() { $container = $this->getContainer(); $container->singleton(Services::HELPERSET, function () use($container) { $helperSet = new HelperSet(); $helperSet->set($container->get(Services::HELPERSET_QUESTION), 'question'); return $helperSet; })->withArgument(Services::CONFIG); $container->add(Services::HELPERSET_QUESTION, QuestionHelper::class); }
/** * read the input and return a Configuration, returns `false` if the config * is not supported * @return Connection|null */ public function chosen() { if ($this->helperSet->has($this->helperName)) { $connectionHelper = $this->helperSet->get($this->helperName); if ($connectionHelper instanceof ConnectionHelper) { return $connectionHelper->getConnection(); } } return null; }
function it_dumps_field_filters(OutputInterface $output, HelperSet $helperSet, TableHelper $table) { $output->writeln(Argument::any())->shouldBeCalled(); $helperSet->get('table')->willReturn($table); $headers = ['field', 'filter_class', 'operators']; $table->setHeaders($headers)->shouldBeCalled()->willReturn($table); $table->setRows(Argument::any())->shouldBeCalled(); $table->render(Argument::any())->shouldBeCalled(); $this->dump($output, $helperSet); }
/** * {@inheritdoc} */ public function ask($question, $default = NULL) { if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_QUIET) { return FALSE; } /** @var QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new ConfirmationQuestion($question, $default); return $helper->ask($this->input, $this->output, $question); }
function it_dumps_field_filters(OutputInterface $output, HelperSet $helperSet, TableHelper $table, $repository) { $output->writeln(Argument::any())->shouldBeCalled(); $repository->findAll()->willReturn([]); $helperSet->get('table')->willReturn($table); $headers = ['attribute', 'localizable', 'scopable', 'attribute type', 'filter_class', 'operators']; $table->setHeaders($headers)->shouldBeCalled()->willReturn($table); $table->setRows(Argument::any())->shouldBeCalled(); $table->render(Argument::any())->shouldBeCalled(); $this->dump($output, $helperSet); }
public function testIteration() { $helperset = new HelperSet(); $helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset)); $helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset)); $helpers = array('fake_helper_01', 'fake_helper_02'); $i = 0; foreach ($helperset as $helper) { $this->assertEquals($helpers[$i++], $helper->getName()); } }
/** * @param HelperSet $helpers * @return TravisCiCommand * @throws \Symfony\Component\Console\Exception\InvalidArgumentException * @throws \Symfony\Component\Console\Exception\LogicException */ public static function createCommand(HelperSet $helpers) { /** @var QuestionHelper $questionHelper */ $questionHelper = $helpers->get('question'); $travisCiQuestionHelper = new TravisCiQuestionHelper($questionHelper); /** @var PackageHelper $packageHelper */ $packageHelper = $helpers->get('package'); $configBuilder = new ConfigBuilder($travisCiQuestionHelper, $packageHelper); $configWriter = new ConfigWriter(); return new TravisCiCommand($travisCiQuestionHelper, $configBuilder, $configWriter); }
function it_should_execute_when_calling_fire_action(QuestionHelper $question, HelperSet $helpers) { $helpers->get('question')->willReturn($question); $input = new ArrayInput([]); $output = new NullOutput(); $query = Argument::type('Symfony\\Component\\Console\\Question\\ChoiceQuestion'); $question->ask($input, $output, $query)->willReturn(1); $helpers->get('question')->willReturn($question); $this->setHelperSet($helpers); $this->run($input, $output); $this->fire(); }
/** * Sets the dojo theme to use. * * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @return \Symfony\Component\Console\Application */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config')['sds']['dojo']; $configHelper = new \Sds\DojoModule\Tools\Console\Helper\ConfigHelper($config); $helperSet = new HelperSet(); $helperSet->set($configHelper, 'config'); $cli = new Application(); $cli->setName('DojoModule Command Line Interface'); $cli->setHelperSet($helperSet); $cli->addCommands(array(new \Sds\DojoModule\Tools\Console\Command\GenerateProfile())); return $cli; }
protected function setUp() { parent::setUp(); $this->application = static::getMock(Application::class); $this->sut = $this->getSut(); $command = static::getMockBuilder(Command::class)->disableOriginalConstructor()->getMock(); $command->expects(static::any())->method('getApplication')->willReturn($this->application); $command->expects(static::any())->method('getName')->willReturn('mock command'); $helperSet = new HelperSet(); $helperSet->setCommand($command); $this->sut->setHelperSet($helperSet); $this->application->setHelperSet($helperSet); }
public function testExecute() { $profiler = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')->disableOriginalConstructor()->getMock(); $profiler->expects($this->once())->method('import')->will($this->returnValue(new Profile('TOKEN'))); $helperSet = new HelperSet(); $helper = $this->getMock('Symfony\\Component\\Console\\Helper\\FormatterHelper'); $helper->expects($this->any())->method('formatSection'); $helperSet->set($helper, 'formatter'); $command = new ImportCommand($profiler); $command->setHelperSet($helperSet); $commandTester = new CommandTester($command); $commandTester->execute(array('filename' => __DIR__ . '/../Fixtures/profile.data')); $this->assertRegExp('/Profile "TOKEN" has been successfully imported\\./', $commandTester->getDisplay()); }
/** * If the user answers yes then we can override the file * or if the file doesn't exist then we will just answer * yes because we aren't overriding anything. * * @param string $filename * @param OutputInterface $output * @param HelperSet $helperSet * @return boolean */ protected function yes($filename, $output, $helperSet, $options) { if (!$this->file->exists($this->basePath . '/' . $filename)) { return true; } if (isset($options['yes']) && $options['yes'] == true) { return true; } $dialog = $helperSet->get('dialog'); if ($dialog->askConfirmation($output, "<question>Would you like to override {$filename}? [y/N]</question>", false)) { return true; } return false; }
/** * {@inheritdoc} */ public function dump(OutputInterface $output, HelperSet $helperSet) { $output->writeln("<info>Useable attributes filters...</info>"); $attributeFilters = $this->getAttributeFilters(); $attributes = $this->repository->findAll(); $rows = []; foreach ($attributes as $attribute) { $rows = array_merge($rows, $this->getFilterInformationForAttribute($attribute, $attributeFilters)); } $table = $helperSet->get('table'); $headers = ['attribute', 'localizable', 'scopable', 'attribute type', 'operators', 'filter_class']; $table->setHeaders($headers)->setRows($rows); $table->render($output); }
/** * Runs the application using the given HelperSet * * This method is responsible for creating the console application, adding * relevant commands, and running it. Other code is responsible for producing * the HelperSet itself (your cli-config.php or bootstrap code), and for * calling this method (the actual bin command file). * * @param HelperSet $helperSet * @param Application $application * @throws \Doxport\Exception\Exception * @return integer 0 if everything went fine, or an error code */ public static function run(HelperSet $helperSet, Application $application = null) { if (!$helperSet->has('em')) { throw new Exception('Helper set passed to Doxport console runner must have an entity manager ("em")'); } if (!$application) { $application = new Application('Doxport relational data tool', Version::VERSION); } $application->setCatchExceptions(true); $application->setHelperSet($helperSet); $application->add(new ExportCommand()); $application->add(new DeleteCommand()); $application->add(new ImportCommand()); return $application->run(); }
public function testExecuteWithToken() { $profiler = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')->disableOriginalConstructor()->getMock(); $profile = new Profile('TOKEN'); $profiler->expects($this->once())->method('loadProfile')->with('TOKEN')->will($this->returnValue($profile)); $helperSet = new HelperSet(); $helper = $this->getMock('Symfony\\Component\\Console\\Helper\\FormatterHelper'); $helper->expects($this->any())->method('formatSection'); $helperSet->set($helper, 'formatter'); $command = new ExportCommand($profiler); $command->setHelperSet($helperSet); $commandTester = new CommandTester($command); $commandTester->execute(array('token' => 'TOKEN')); $this->assertEquals($profiler->export($profile), $commandTester->getDisplay()); }
protected function setUp() { parent::setUp(); $this->inputMock = static::getMock(InputInterface::class); $this->outputMock = static::getMock(OutputInterface::class); $this->packageMock = static::getMock(PackageHelper::class); $this->requireMock = static::getMock(RequireHelper::class); $this->questionMock = Mockery::mock(QuestionHelper::class)->makePartial(); $helperSet = new HelperSet(); $helperSet->set($this->questionMock, 'question'); $helperSet->set($this->packageMock, 'package'); $helperSet->set($this->requireMock, 'composer require'); $this->sut = new CodeSnifferCommand(); $this->sut->setHelperSet($helperSet); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->get('entity_manager'); $helperSet = new HelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); $arguments = array(); if ($input->getOption('dump-sql')) { $arguments['--dump-sql'] = $input->getOption('dump-sql'); } $command = new CreateCommand(); $command->setHelperSet($helperSet); $returnCode = $command->run(new ArrayInput($arguments), $output); return $returnCode; }
/** * Mocks question helper. */ protected function mockQuestionHelper(array $answers) { foreach ($answers as $key => $answer) { $this->questionHelper->expects($this->at($key + 2))->method('ask')->will($this->returnValue($answer)); } $this->helperSet->set($this->questionHelper, 'question'); }
/** * {@inheritdoc} */ public function dump(OutputInterface $output, HelperSet $helperSet) { $output->writeln("<info>Useable field filters...</info>"); $rows = []; foreach ($this->registry->getFieldFilters() as $filter) { $class = get_class($filter); $operators = implode(', ', $filter->getOperators()); foreach ($filter->getFields() as $field) { $rows[] = [$field, $operators, $class]; } } $headers = ['field', 'operators', 'filter_class']; $table = $helperSet->get('table'); $table->setHeaders($headers)->setRows($rows); $table->render($output); }
/** * {@inheritDoc} */ public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) { if ($this->isInteractive()) { return $this->helperSet->get('dialog')->select($this->getErrorOutput(), $question, $choices, $default, $attempts, $errorMessage, $multiselect); } return $default; }
/** * Asks user to choose. * * @param string $question The question to ask. * @param array $options Valid answer options. * @param mixed $default Default answer. * @param string $error_message Error on incorrect answer. * * @return mixed */ public function choose($question, array $options, $default, $error_message) { /** @var QuestionHelper $helper */ $helper = $this->_helperSet->get('question'); $choice_question = new ChoiceQuestion('<question>' . $question . '</question> ', $options, $default); $choice_question->setErrorMessage($error_message); return $helper->ask($this->_input, $this->_output, $choice_question); }
function it_dumps_field_filters($registry, OutputInterface $output, HelperSet $helperSet, TableHelper $table, FieldFilterInterface $groupFilter) { $output->writeln(Argument::any())->shouldBeCalled(); $operators = ['IN', 'NOT IN', 'EMPTY', 'NOT EMPTY']; $fields = ['groups.id', 'groups.code']; $registry->getFieldFilters()->willReturn([$groupFilter]); $groupFilter->getOperators()->willReturn($operators); $groupFilter->getFields()->willReturn($fields); $helperSet->get('table')->willReturn($table); $headers = ['field', 'operators', 'filter_class']; $table->setHeaders($headers)->shouldBeCalled()->willReturn($table); $table->setRows(Argument::that(function ($param) { return 'groups.id' === $param[0][0] && 'IN, NOT IN, EMPTY, NOT EMPTY' === $param[0][1] && false !== strpos($param[0][2], 'FieldFilterInterface') && 'groups.code' === $param[1][0] && 'IN, NOT IN, EMPTY, NOT EMPTY' === $param[1][1] && false !== strpos($param[1][2], 'FieldFilterInterface'); }))->shouldBeCalled(); $table->render(Argument::any())->shouldBeCalled(); $this->dump($output, $helperSet); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->get('entity_manager'); $helperSet = new HelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); $arguments = array(); if ($input->getOption('editor-cmd')) { $arguments['--editor-cmd'] = $input->getOption('editor-cmd'); } $configDir = $this->get('config')->get('[directories][config_dir]'); $arguments['--configuration'] = $configDir . '/migrations.yml'; $command = new GenerateCommand(); $command->setHelperSet($helperSet); $returnCode = $command->run(new ArrayInput($arguments), $output); return $returnCode; }