/** * {@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); }
/** * @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); }
/** * 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; }
/** * {@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); }
/** * @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(); }
/** * {@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(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); }
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); }
function it_should_execute_when_calling_fire_action(QuestionHelper $question, HelperSet $helpers) { $app = Mockery::mock('Illuminate\\Contracts\\Foundation\\Application'); $app->shouldReceive('call')->andReturn(true); $input = Mockery::mock('Symfony\\Component\\Console\\Input\\ArrayInput'); $input->shouldReceive('bind'); $input->shouldReceive('isInteractive')->andReturn(false); $input->shouldReceive('hasArgument')->andReturn(false); $input->shouldReceive('validate')->andReturn(false); $input->shouldReceive('getOption')->andReturn(false); $this->setLaravel($app); $helpers->get('question')->willReturn($question); $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(); }
/** * 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); }
/** * {@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); }
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); }
public function testGet() { $helper_01 = $this->getGenericMockHelper('fake_helper_01'); $helper_02 = $this->getGenericMockHelper('fake_helper_02'); $helperset = new HelperSet(array('fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02)); $this->assertEquals($helper_01, $helperset->get('fake_helper_01'), '->get() returns correct helper by name'); $this->assertEquals($helper_01, $helperset->get('fake_helper_01_alias'), '->get() returns correct helper by alias'); $this->assertEquals($helper_02, $helperset->get('fake_helper_02'), '->get() returns correct helper by name'); $this->assertEquals($helper_02, $helperset->get('fake_helper_02_alias'), '->get() returns correct helper by alias'); $helperset = new HelperSet(); try { $helperset->get('foo'); $this->fail('->get() throws \\InvalidArgumentException when helper not found'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->get() throws \\InvalidArgumentException when helper not found'); $this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \\InvalidArgumentException when helper not found'); } }
/** * {@inheritdoc} */ public function dump(OutputInterface $output, HelperSet $helperSet) { $output->writeln("<info>Useable field filters...</info>"); $fields = ['id', 'created', 'updated', 'enabled', 'completeness', 'family.id', 'family.code', 'groups.id', 'groups.code', 'categories.id', 'categories.code']; $rows = []; foreach ($fields as $field) { $filter = $this->registry->getFieldFilter($field); if ($filter) { $class = get_class($filter); $operators = implode(', ', $filter->getOperators()); } else { $class = 'Not supported'; $operators = ''; } $rows[] = [$field, $class, $operators]; } $headers = ['field', 'filter_class', 'operators']; $table = $helperSet->get('table'); $table->setHeaders($headers)->setRows($rows); $table->render($output); }
protected function _doRun(HelperSet $helperSet) { if ($this->installSqlFile === null) { throw new \BuildException("Schema SQL file is not set."); } if (!is_dir(dirname($this->installSqlFile))) { throw new \BuildException("Schema SQL directory is not a valid directory."); } if (!is_writable(dirname($this->installSqlFile))) { throw new \BuildException("Schema SQL directory is not writable."); } $emHelper = $helperSet->get('em'); $em = $emHelper->getEntityManager(); $schemaTool = new SchemaTool($em); $cmf = $em->getMetadataFactory(); $classes = $cmf->getAllMetadata(); $sql = $schemaTool->getCreateSchemaSql($classes); $code = sprintf("<?php\n\nreturn %s;\n", var_export($sql, true)); file_put_contents($this->installSqlFile, $code); $this->log("Wrote schema SQL to file {$this->installSqlFile}"); }
/** * {@inheritdoc} */ public function dump(OutputInterface $output, HelperSet $helperSet) { $output->writeln("<info>Useable attributes filters...</info>"); $attributes = $this->repository->findAll(); $rows = []; foreach ($attributes as $attribute) { $field = $attribute->getCode(); $filter = $this->registry->getAttributeFilter($attribute); if ($filter) { $class = get_class($filter); $operators = implode(', ', $filter->getOperators()); } else { $class = 'Not supported'; $operators = ''; } $rows[] = [$field, $attribute->isLocalizable() ? 'yes' : 'no', $attribute->isScopable() ? 'yes' : 'no', $attribute->getAttributeType(), $class, $operators]; } $table = $helperSet->get('table'); $headers = ['attribute', 'localizable', 'scopable', 'attribute type', 'filter_class', 'operators']; $table->setHeaders($headers)->setRows($rows); $table->render($output); }
function it_dumps_reference_data_filter($repository, $registry, OutputInterface $output, HelperSet $helperSet, TableHelper $table, AttributeFilterInterface $refDataFilter, AttributeInterface $refDataAttribute) { $output->writeln(Argument::any())->shouldBeCalled(); $repository->findAll()->willReturn([$refDataAttribute]); $registry->getAttributeFilters()->willReturn([$refDataFilter]); $refDataFilter->getAttributeTypes()->willReturn([]); $operators = ['IN', 'EMPTY']; $refDataFilter->getOperators()->willReturn($operators); $refDataFilter->supportsAttribute($refDataAttribute)->willReturn(true); $refDataAttribute->getCode()->willReturn('ref_data'); $refDataAttribute->getAttributeType()->willReturn(AttributeTypes::REFERENCE_DATA_MULTI_SELECT); $refDataAttribute->isScopable()->willReturn(false); $refDataAttribute->isLocalizable()->willReturn(false); $refDataAttribute->isBackendTypeReferenceData()->willReturn(true); $helperSet->get('table')->willReturn($table); $headers = ['attribute', 'localizable', 'scopable', 'attribute type', 'operators', 'filter_class']; $table->setHeaders($headers)->shouldBeCalled()->willReturn($table); $table->setRows(Argument::that(function ($param) { return 'ref_data' === $param[0][0] && 'no' === $param[0][1] && 'no' === $param[0][2] && AttributeTypes::REFERENCE_DATA_MULTI_SELECT === $param[0][3] && 'IN, EMPTY' === $param[0][4] && false !== strpos($param[0][5], 'AttributeFilterInterface'); }))->shouldBeCalled(); $table->render(Argument::any())->shouldBeCalled(); $this->dump($output, $helperSet); }
protected function _doRun(HelperSet $helperSet) { $emHelper = $helperSet->get('em'); $em = $emHelper->getEntityManager(); $cmf = $em->getMetadataFactory(); $classes = $cmf->getAllMetadata(); $factory = $em->getProxyFactory(); if (empty($classes)) { $this->log('No classes to generate proxies for.'); } else { $proxyDir = $this->proxyDir !== null ? $this->proxyDir : $em->getConfiguration()->getProxyDir(); if ($proxyDir === null) { throw new \BuildException("Proxy directory is not set."); } if (!is_dir($proxyDir)) { throw new \BuildException("Proxy directory is not a valid directory."); } if (!is_writable($proxyDir)) { throw new \BuildException("Proxy directory is not writable."); } $factory->generateProxyClasses($classes, $proxyDir); $this->log("Doctrine 2 proxy classes generated to {$proxyDir}"); } }
/** * Returns a Dialog helper. * * @return DialogHelper */ public function getDialog() { return $this->helperSet->get('dialog'); }
public function createConfigurator(HelperSet $helperSet, Config $config) { return new GitHubConfigurator($helperSet->get('question'), 'GitHub issue tracker', 'https://api.github.com/', 'https://github.com'); }
/** * @param HelperSet $helperSet * * @return QuestionHelper */ private function questionHelper(HelperSet $helperSet) { return $helperSet->get('question'); }
public function createConfigurator(HelperSet $helperSet, Config $config) { $configurator = new BitBucketConfigurator($helperSet->get('question'), 'Bitbucket', 'https://bitbucket.org/api/', 'https://bitbucket.org'); return $configurator; }
function let(TaskRunner $taskRunner, EventDispatcherInterface $eventDispatcher, HelperSet $helperSet, PathsHelper $pathsHelper) { $this->beConstructedWith($taskRunner, $eventDispatcher); $helperSet->get(PathsHelper::HELPER_NAME)->willreturn($pathsHelper); $this->setHelperSet($helperSet); }
/** * @param HelperSet $helperSet * * @return DefaultConfigurator */ public static function createIssueTrackerConfigurator(HelperSet $helperSet) { return new DefaultConfigurator($helperSet->get('question'), 'Jira Enterprise issue tracker', 'http://jira.domain.net:8081/rest/api/2/', 'http://jira.domain.net:8081/'); }
/** * Creates a new Configurator instance for the gitlab adapter. * * @param HelperSet $helperSet HelperSet object * * @return Configurator */ public static function createAdapterConfigurator(HelperSet $helperSet) { return new GitlabConfigurator($helperSet->get('question'), 'Gitlab', 'http://gitlab-host/api/v3', 'http://gitlab-host', [['Token', Configurator::AUTH_HTTP_TOKEN]]); }
<?php // This file is not a CODE, it makes no sense and won't run or validate // Its AST serves PHPStorm IDE as DATA source to make advanced type inference decisions. // @codingStandardsIgnoreFile namespace PHPSTORM_META; $STATIC_METHOD_TYPES = [\Symfony\Component\Console\Helper\HelperSet::get('') => ['php_bin_get' instanceof \Rikby\Console\Helper\PhpBinHelper, 'simple_question' instanceof \Rikby\Console\Helper\SimpleQuestionHelper, 'git_dir_get' instanceof \Rikby\Console\Helper\GitDirHelper, 'question' instanceof \Symfony\Component\Console\Helper\SymfonyQuestionHelper, 'process' instanceof \Symfony\Component\Console\Helper\ProcessHelper, 'debug_formatter' instanceof \Symfony\Component\Console\Helper\DebugFormatterHelper, 'descriptor' instanceof \Symfony\Component\Console\Helper\DescriptorHelper, 'code_validator' instanceof \PreCommit\Console\Helper\ValidatorHelper, 'commithook_config' instanceof \PreCommit\Console\Helper\ConfigHelper, 'commithook_config_set' instanceof \PreCommit\Console\Helper\Config\SetHelper, 'commithook_config_writer' instanceof \PreCommit\Console\Helper\Config\WriterHelper, 'commithook_config_file' instanceof \PreCommit\Console\Helper\Config\FileFilterHelper]];