public function testShouldNotClearScreenInNotInteractiveMode() { $SUT = $this->createSUT(); $this->input->setInteractive(false); $SUT->cls(); $this->assertEquals('', $this->output->fetch()); }
/** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ public function doRun(InputInterface $input, OutputInterface $output) { $output->writeLn($this->getHeader()); $name = $this->getCommandName($input); if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->run(); return 0; } if (true === $input->hasParameterOption(array('--ansi'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'))) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--help', '-h'))) { if (!$name) { $name = 'help'; $input = new ArrayInput(array('command' => 'help')); } else { $this->wantHelps = true; } } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } if (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); if (!posix_isatty($inputStream)) { $input->setInteractive(false); } } if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } if (true === $input->hasParameterOption(array('--version', '-V'))) { $output->writeln($this->getLongVersion()); return 0; } if (!$name) { $name = 'list'; $input = new ArrayInput(array('command' => 'list')); } // the command name MUST be the first element of the input $command = $this->find($name); $this->runningCommand = $command; $statusCode = $command->run($input, $output); $this->runningCommand = null; # write Footer $output->writeLn($this->getFooter()); return is_numeric($statusCode) ? $statusCode : 0; }
protected function execute(InputInterface $input, OutputInterface $output) { if ($this->isEnabled()) { $bundleName = $input->getArgument("bundle"); $bundle = $this->getContainer()->get('kernel')->getBundle($bundleName); /* @var $bundle BundleInterface */ $entities = array(); foreach ($this->getBundleMetadata($bundle) as $m) { /* @var $m ClassMetadata */ $_tmp = explode('\\', $m->getName()); $entityName = array_pop($_tmp); $entities[$bundleName . ':' . $entityName] = $entityName; } $command = $this->getApplication()->find('itscaro:generate:crud'); foreach ($entities as $entityShortcut => $entityName) { try { $_input = new ArrayInput(['command' => 'itscaro:generate:crud', '--entity' => $entityShortcut, '--route-prefix' => $input->getOption('route-prefix') . strtolower($entityName), '--with-write' => $input->getOption('with-write'), '--format' => $input->getOption('format'), '--overwrite' => $input->getOption('overwrite')]); $_input->setInteractive($input->isInteractive()); $output->writeln("<info>Executing:</info> {$_input}"); $returnCode = $command->run($_input, $output); $output->writeln("\t<info>Done</info>"); } catch (\Exception $e) { $output->writeln("\t<error>Error:</error> " . $e->getMessage()); } } } else { $output->writeln('<error>Cannot find DoctrineBundle</error>'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $command = $this->getApplication()->find('translations:fetch'); $arguments = array('command' => 'translations:fetch', '--username' => $input->getOption('username'), '--password' => $input->getOption('password'), '--keep-english' => true); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, $output); $englishFromOTrance = FetchFromOTrance::getDownloadPath() . DIRECTORY_SEPARATOR . 'en.json'; if (!file_exists($englishFromOTrance)) { $output->writeln("English file from oTrance missing. Aborting"); return; } $englishFromOTrance = json_decode(file_get_contents($englishFromOTrance), true); Translate::reloadLanguage('en'); $availableTranslations = $GLOBALS['Piwik_translations']; $categories = array_unique(array_merge(array_keys($englishFromOTrance), array_keys($availableTranslations))); sort($categories); $unnecessary = $outdated = $missing = array(); foreach ($categories as $category) { if (!empty($englishFromOTrance[$category])) { foreach ($englishFromOTrance[$category] as $key => $value) { if (!array_key_exists($category, $availableTranslations) || !array_key_exists($key, $availableTranslations[$category])) { $unnecessary[] = sprintf('%s_%s', $category, $key); continue; } else { if (html_entity_decode($availableTranslations[$category][$key]) != html_entity_decode($englishFromOTrance[$category][$key])) { $outdated[] = sprintf('%s_%s', $category, $key); continue; } } } } if (!empty($availableTranslations[$category])) { foreach ($availableTranslations[$category] as $key => $value) { if (!array_key_exists($category, $englishFromOTrance) || !array_key_exists($key, $englishFromOTrance[$category])) { $missing[] = sprintf('%s_%s', $category, $key); continue; } } } } $output->writeln(""); if (!empty($missing)) { $output->writeln("<bg=yellow;options=bold>-- Following keys are missing on oTrance --</bg=yellow;options=bold>"); $output->writeln(implode("\n", $missing)); $output->writeln(""); } if (!empty($unnecessary)) { $output->writeln("<bg=yellow;options=bold>-- Following keys might be unnecessary on oTrance --</bg=yellow;options=bold>"); $output->writeln(implode("\n", $unnecessary)); $output->writeln(""); } if (!empty($outdated)) { $output->writeln("<bg=yellow;options=bold>-- Following keys are outdated on oTrance --</bg=yellow;options=bold>"); $output->writeln(implode("\n", $outdated)); $output->writeln(""); } $output->writeln("Finished."); }
/** * Run doctrine migrations */ protected function handleMigrations() { $application = $this->getApplication(); $commandInput = new ArrayInput(array('command' => 'doctrine:migrations:migrate')); $commandInput->setInteractive(false); $application->doRun($commandInput, $this->output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $file = 'build/portable-zip-api.zip'; $pharCommand = $this->getApplication()->find('build:phar'); $arrayInput = new ArrayInput(array('command' => 'build:phar')); $arrayInput->setInteractive(false); if ($pharCommand->run($arrayInput, $output)) { $output->writeln('The operation is aborted due to build:phar command'); return 1; } if (file_exists($file)) { $output->writeln('Removing previous package'); unlink($file); } $zip = new \ZipArchive(); if ($zip->open($file, \ZipArchive::CREATE) !== true) { $output->writeln('Failed to open zip archive'); return 1; } $zip->addFile('build/zip.phar.php', 'zip.phar.php'); $zip->addFile('app/zip.sqlite.db', 'zip.sqlite.db'); $zip->addFile('README.md', 'README.md'); $zip->close(); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $force = (bool) $input->getOption('force'); $dialog = $this->getHelperSet()->get('dialog'); // Doctrine create database if ($force || $dialog->askConfirmation($output, '<question>Create Database?</question>', false)) { $output->writeln('Creating database...'); $command = $this->getApplication()->find('doctrine:database:create'); $input = new ArrayInput(['command' => 'doctrine:database:create', '-n' => $force]); $returnCode = $command->run($input, $output); } // Doctrine schema update if ($force || $dialog->askConfirmation($output, '<question>Load Schema?</question>', false)) { $output->writeln('Loading Schema...'); $command = $this->getApplication()->find('doctrine:schema:update'); $input = new ArrayInput(['command' => 'doctrine:schema:update', '--force' => true, '-n' => $force]); $returnCode = $command->run($input, $output); } // Doctrine Fixtures if ($force || $dialog->askConfirmation($output, '<question>Load Fixtures?</question>', false)) { $output->writeln('Loading Fixtures...'); $command = $this->getApplication()->find('doctrine:fixtures:load'); $input = new ArrayInput(['doctrine:fixtures:load']); $input->setInteractive(!$force); $returnCode = $command->run($input, $output); } $output->writeln('Finished.'); }
/** * Prepare the input interface for the command. * * @return InputInterface */ protected function prepareInput() { $arguments = ['--optimize' => (bool) $this->file->get(self::SETTING_OPTIMIZE), '--no-dev' => true]; $input = new ArrayInput($arguments); $input->setInteractive(false); return $input; }
public function testBuildCommands() { $definition = new CommandDefinition('self-update'); $definition->setDescription('Update spress.phar to the latest version.'); $definition->setHelp('The self-update command replace your spress.phar by the latest version.'); $definition->addOption('all'); $definition->addArgument('dir'); $input = new ArrayInput([]); $input->setInteractive(false); $output = new StreamOutput(fopen('php://memory', 'w', false)); $commandPluginMock = $this->getMockBuilder('\\Yosymfony\\Spress\\Plugin\\CommandPlugin')->getMock(); $commandPluginMock->expects($this->once())->method('getCommandDefinition')->will($this->returnValue($definition)); $commandPluginMock->expects($this->once())->method('executeCommand'); $pm = new PluginManager(new EventDispatcher()); $pm->getPluginCollection()->add('emptyCommandPlugin', $commandPluginMock); $builder = new ConsoleCommandBuilder($pm); $symfonyConsoleCommands = $builder->buildCommands(); $this->assertTrue(is_array($symfonyConsoleCommands)); $this->assertCount(1, $symfonyConsoleCommands); $this->assertContainsOnlyInstancesOf('Symfony\\Component\\Console\\Command\\Command', $symfonyConsoleCommands); $symfonyConsoleCommand = $symfonyConsoleCommands[0]; $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getOptions()); $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getArguments()); $this->assertEquals('Update spress.phar to the latest version.', $symfonyConsoleCommand->getDescription()); $this->assertEquals('The self-update command replace your spress.phar by the latest version.', $symfonyConsoleCommand->getHelp()); $symfonyConsoleCommand->run($input, $output); }
/** * @param ConsoleTerminateEvent $event */ public function callCommands(ConsoleTerminateEvent $event) { /** * @var \Drupal\Console\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); if (!$command instanceof Command) { return; } $application = $command->getApplication(); $commands = $application->getChain()->getCommands(); if (!$commands) { return; } foreach ($commands as $chainedCommand) { if ($chainedCommand['name'] == 'module:install') { $messageHelper = $application->getMessageHelper(); $translatorHelper = $application->getTranslator(); $messageHelper->addErrorMessage($translatorHelper->trans('commands.chain.messages.module_install')); continue; } $callCommand = $application->find($chainedCommand['name']); $input = new ArrayInput($chainedCommand['inputs']); if (!is_null($chainedCommand['interactive'])) { $input->setInteractive($chainedCommand['interactive']); } $callCommand->run($input, $output); } }
private function executeCommand($command, $arguments, OutputInterface $output) { $command = $this->getApplication()->find($command); $arguments['command'] = $command; $input = new ArrayInput($arguments); $input->setInteractive(false); return $command->run($input, $output); }
protected function launchImportCommand() { $app = new Application(self::$container->get('kernel')); $app->setAutoExit(false); $input = new ArrayInput(array('command' => 'modera:translations:import')); $input->setInteractive(false); $exitCode = $app->run($input, new NullOutput()); $this->assertEquals(0, $exitCode); }
/** * @param null|string|array $config */ private function launchCommand($config = null) { $app = new Application(self::$kernel->getContainer()->get('kernel')); $app->setAutoExit(false); $input = new ArrayInput(array('command' => 'modera:languages:config-sync-dummy', 'config' => $config ? json_encode($config) : null)); $input->setInteractive(false); $result = $app->run($input, new NullOutput()); $this->assertEquals(0, $result); }
function executeCommand($application, $command, array $options = array()) { $options["--env"] = "test"; $options["--quiet"] = true; $options = array_merge($options, array('command' => $command)); $arrayInput = new ArrayInput($options); $arrayInput->setInteractive(false); $application->run($arrayInput); }
public function update($name) { $app = new Application(); $app->setAutoExit(false); $input = new ArrayInput(['update', 'packages' => [$name]]); $input->setInteractive(false); $output = new BufferedOutput(); $app->run($input, $output); return $output->fetch(); }
/** * {@inheritDoc} */ protected function prepareInput() { $arguments = []; if ($this->isSelectiveUpgrade()) { $arguments['packages'] = $this->getPackages(); } $input = new ArrayInput($arguments); $input->setInteractive(false); return $input; }
/** * {@inheritDoc} */ protected function prepareInput() { $arguments = ['packages' => $this->getPackage()]; if ($this->isNoUpdate()) { $arguments['no-update'] = ''; } $input = new ArrayInput($arguments); $input->setInteractive(false); return $input; }
protected function executeCommand(OutputInterface $output, $arguments) { $app = $this->getApplication(); $input = new ArrayInput($arguments); $input->setInteractive(false); $returnCode = $app->doRun($input, $output); if ($returnCode == 0) { return true; } return false; }
public function runCommands() { foreach ($this->commands as &$command) { if ($command['once'] && $command['runCount'] > 0) { continue; } $input = new ArrayInput($command['options']); $input->setInteractive(false); $this->application->run($input, $this->output); $command['runCount']++; } }
private function loadSchemaUpdateVersions(InputInterface $input, OutputInterface $output) { $app = $this->getApplication(); $input = new ArrayInput(array('command' => 'doctrine:migrations:version', '--add' => true, '--all' => true)); $input->setInteractive(false); $returnCode = $app->doRun($input, $output); if ($returnCode == 0) { return true; } else { return false; } }
protected function runCommand($name, array $params = array()) { \array_unshift($params, $name); $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->setAutoExit(false); $input = new ArrayInput($params); $input->setInteractive(false); $ouput = new NullOutput(0); $application->run($input, $ouput); }
/** * @param $name * @param array $params * @return int Command exit code * @throws \Exception * */ private static function runCommandStatic($name, array $params = array()) { array_unshift($params, $name); $input = new ArrayInput($params); $input->setInteractive(false); $fp = fopen('php://temp/maxmemory', 'r+'); $output = new StreamOutput($fp); self::getApplication()->run($input, $output); rewind($fp); $returnOutput = stream_get_contents($fp); return $returnOutput; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $consumers = ['google_create', 'google_update', 'google_delete']; if (null !== ($consumer = $input->getArgument('consumer'))) { $consumers = [$consumer]; } foreach ($consumers as $consumer) { $output->writeln(sprintf('Request to purge sent to %s', $consumer)); $inputCommand = new ArrayInput(['command' => 'rabbitmq:purge', 'name' => $consumer]); $inputCommand->setInteractive(false); $this->getApplication()->doRun($inputCommand, $output); $output->writeln(sprintf('<info>Consumer %s purged</info>', $consumer)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->getApplication()->getConfig(); foreach ($config['models'] as $className => $model) { if (is_array($model)) { $arrayInputArgs = ['modelName' => $model["modelName"]]; } else { $arrayInputArgs = ['modelName' => $model]; } $command = $this->getApplication()->find('generate:config'); $arrayInput = new ArrayInput($arrayInputArgs, $command->getNativeDefinition()); $arrayInput->setInteractive(true); $command->execute($arrayInput, $output); } }
/** * Execute the command * * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Do you really want to reinstall packy? All data will be lost. (y/n) ', false); if (!$helper->ask($input, $output, $question)) { return; } $command = $this->getApplication()->find('doctrine:database:drop'); $arguments = array('command' => 'doctrine:database:drop', '--force' => true, '--quiet' => true); $input = new ArrayInput($arguments); $input->setInteractive(false); $command->run($input, $output); $installCommand = $this->getApplication()->find('packy:install'); $arguments = array('command' => 'packy:install'); $installInput = new ArrayInput($arguments); $installCommand->run($installInput, $output); }
/** * Execute the command * * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $command = $this->getApplication()->find('doctrine:database:create'); $arguments = array('command' => 'doctrine:database:create', '--if-not-exists' => true, '--quiet' => true); $input = new ArrayInput($arguments); $input->setInteractive(false); $command->run($input, $output); $command = $this->getApplication()->find('doctrine:migrations:migrate'); $arguments = array('command' => 'doctrine:migrations:migrate', '--quiet' => true); $input = new ArrayInput($arguments); $input->setInteractive(false); $command->run($input, $output); $userCommand = $this->getApplication()->find('fos:user:create'); $arguments = array('command' => 'fos:user:create', '--super-admin' => true); $input = new ArrayInput($arguments); $userCommand->run($input, $output); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (PHP_SAPI !== 'cli') { echo 'Warning: Composer should be invoked via the CLI version of PHP, not the ' . PHP_SAPI . ' SAPI' . PHP_EOL; } error_reporting(-1); if (function_exists('ini_set')) { @ini_set('display_errors', 1); $memoryInBytes = function ($value) { $unit = strtolower(substr($value, -1, 1)); $value = (int) $value; switch ($unit) { case 'g': $value *= 1024; // no break (cumulative multiplier) // no break (cumulative multiplier) case 'm': $value *= 1024; // no break (cumulative multiplier) // no break (cumulative multiplier) case 'k': $value *= 1024; } return $value; }; $memoryLimit = trim(ini_get('memory_limit')); // Increase memory_limit if it is lower than 1GB if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1024) { @ini_set('memory_limit', '1G'); } unset($memoryInBytes, $memoryLimit); } if (is_callable([$this->input, '__toString'])) { // strip "composer " $token = substr($this->input->__toString(), 9); $input = new StringInput($token); } else { $arguments = $this->argument(); $input = new ArrayInput($arguments['params']); } $input->setInteractive(false); // run the command application $application = @new Application(); $application->run($input); }
/** * Execute a command. */ protected function execCommand($description, $command, $args = ['']) { $this->output->getFormatter()->setIndentLevel(1); if (!empty($args)) { $this->output->writeln(sprintf('<comment>%s </comment> (%s)', $command, json_encode($args))); } else { $this->output->writeln(sprintf('<comment>%s</comment>', $command)); } $this->output->writeln(''); $args['command'] = $command; $command = $this->application->find($command); $input = new ArrayInput($args); $input->setInteractive(false); $this->output->getFormatter()->setIndentLevel(2); $res = $command->run($input, $this->output); $this->output->writeln(''); return $res; }
protected function execute(InputInterface $input, OutputInterface $output) { $phpCovPath = trim(shell_exec('which phpcov')); if (empty($phpCovPath)) { $output->writeln('phpcov not installed. please install pear.phpunit.de/phpcov.'); return; } $command = $this->getApplication()->find('tests:run'); $arguments = array('command' => 'tests:run', '--options' => sprintf('--coverage-php %s/tests/results/logs/%%suite%%%%group%%.cov', PIWIK_DOCUMENT_ROOT)); $suite = $input->getOption('testsuite'); if (!empty($suite)) { $arguments['--testsuite'] = $suite; } $groups = $input->getArgument('group'); if (!empty($groups)) { $arguments['group'] = $groups; } else { shell_exec(sprintf('rm %s/tests/results/logs/*.cov', PIWIK_DOCUMENT_ROOT)); } $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, $output); $command = 'phpcov'; // force xdebug usage for coverage options if (!extension_loaded('xdebug')) { $output->writeln('<info>xdebug extension required for code coverage.</info>'); $output->writeln('<info>searching for xdebug extension...</info>'); $extensionDir = shell_exec('php-config --extension-dir'); $xdebugFile = trim($extensionDir) . DIRECTORY_SEPARATOR . 'xdebug.so'; if (!file_exists($xdebugFile)) { $dialog = $this->getHelperSet()->get('dialog'); $xdebugFile = $dialog->askAndValidate($output, 'xdebug not found. Please provide path to xdebug.so', function ($xdebugFile) { return file_exists($xdebugFile); }); } else { $output->writeln('<info>xdebug extension found in extension path.</info>'); } $output->writeln("<info>using {$xdebugFile} as xdebug extension.</info>"); $command = sprintf('php -d zend_extension=%s %s', $xdebugFile, $phpCovPath); } shell_exec(sprintf('rm -rf %s/tests/results/coverage/*', PIWIK_DOCUMENT_ROOT)); passthru(sprintf('cd %1$s && %2$s --merge --html tests/results/coverage/ --whitelist ./core/ --whitelist ./plugins/ --add-uncovered %1$s/tests/results/logs/', PIWIK_DOCUMENT_ROOT, $command)); }
/** * @param InputInterface $input * @param OutputInterface $output * * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $application = $this->getApplication(); $commands = ['artevelde:database:user', 'doctrine:database:create', 'doctrine:schema:create']; if ($input->getOption('migrate')) { $commands[] = 'doctrine:migrations:migrate'; } if ($input->getOption('seed')) { $commands[] = 'doctrine:fixtures:load'; } foreach ($commands as $commandName) { $parameters = ['command' => $commandName]; $commandInput = new ArrayInput($parameters); if (in_array($commandName, ['doctrine:fixtures:load', 'doctrine:migrations:migrate'])) { $commandInput->setInteractive(false); } $application->find($commandName)->run($commandInput, $output); } }