setAutoExit() публичный метод

Sets whether to automatically exit after a command execution or not.
public setAutoExit ( boolean $boolean )
$boolean boolean Whether to automatically exit after a command execution or not
Пример #1
0
 public function setUp()
 {
     parent::setUp();
     $_SERVER['PHWOOLCON_MIGRATION_PATH'] = TEST_ROOT_PATH . '/bin/migrations';
     $this->cli = Cli::register($this->di);
     $this->cli->setAutoExit(false);
     $this->output = new BufferedOutput();
 }
Пример #2
0
 /**
  * Services constructor.
  */
 public function __construct()
 {
     $this->kernel = new Kernel();
     $this->application = new Application('Neusta Facilior', FACILIOR_VERSION);
     $this->application->setAutoExit(false);
     //Creates Services Output
     $this->console = new ConsoleService();
     //Loads Commands into Application
     $this->application->addCommands($this->kernel->commands());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->app = new Application();
     $this->app->setAutoExit(false);
     $this->app->add(new GenerateKeyCommand());
     $this->filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . '/test.key';
     if (file_exists($this->filename)) {
         unlink($this->filename);
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function runCommand($command, $params = [])
 {
     $params = array_merge(['command' => $command], $params, $this->getDefaultParams());
     $this->application->setAutoExit(false);
     $exitCode = $this->application->run(new ArrayInput($params), $this->output);
     if (0 !== $exitCode) {
         $this->application->setAutoExit(true);
         $errorMessage = sprintf('The command terminated with an error code: %u.', $exitCode);
         $this->output->writeln("<error>{$errorMessage}</error>");
         $e = new \Exception($errorMessage, $exitCode);
         throw $e;
     }
     return $this;
 }
Пример #5
0
 /**
  * @param $command
  * @param array $parameters
  * @param OutputInterface $output
  *
  * @return $this
  *
  * @throws \Exception
  */
 public function runCommand($command, $parameters = array(), OutputInterface $output = null)
 {
     $parameters = array_merge(array('command' => $command), $this->getDefaultParameters(), $parameters);
     $this->application->setAutoExit(false);
     $exitCode = $this->application->run(new ArrayInput($parameters), $output ?: new NullOutput());
     if (0 !== $exitCode) {
         $this->application->setAutoExit(true);
         $errorMessage = sprintf('The command terminated with an error code: %u.', $exitCode);
         $this->output->writeln("<error>{$errorMessage}</error>");
         $exception = new \Exception($errorMessage, $exitCode);
         throw $exception;
     }
     return $this;
 }
Пример #6
0
 /**
  * command应用主入口
  * @throws \Exception
  */
 static function main()
 {
     $application = new Application();
     $application->setAutoExit(true);
     $application->addCommands(self::createCommands());
     $application->run();
 }
Пример #7
0
Файл: Tg.php Проект: twhiston/tg
 /**
  * @param null $input Input
  * @return int|void
  * @throws \Exception
  *
  * Run tg and return an error code
  */
 public function run($input = null)
 {
     register_shutdown_function([$this, 'shutdown']);
     set_error_handler([$this, 'handleError']);
     if ($this->classCache->getCachePath() === null) {
         $this->classCache->setCachePath(__DIR__ . "/../.tg/");
     }
     $hasCommandFile = $this->autoloadCommandFile();
     $this->setupDevModes();
     $this->input = $this->prepareInput($input ? $input : $_SERVER['argv']);
     //Load all our commands
     $commandLoader = new CommandLoader();
     $this->loadLocalFile($commandLoader, $hasCommandFile);
     //Cwd project specific
     $this->loadCoreCommands($commandLoader);
     //Tg vendor and core
     if (!$this->coreDevMode) {
         //If we are developing in the core we dont want to load cwd vendors folder at all
         $this->loadLocalVendors($commandLoader);
         //Cwd vendor
     }
     if ($this->libDevMode) {
         //If we are developing a library we want to load the cwd source folder
         $this->loadLocalSrc($commandLoader);
     }
     //Set up the robo static config class :(
     Config::setInput($this->input);
     Config::setOutput($this->output);
     $this->app->setAutoExit(false);
     return $this->app->run($this->input, $this->output);
 }
 protected function executeCommand($command)
 {
     // Cache can not be warmed up as classes can not be redefined during one request
     if (preg_match('/^cache:clear/', $command)) {
         $command .= ' --no-warmup';
     }
     $input = new StringInput($command);
     $input->setInteractive(false);
     $output = new StringOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatterDecorator($formatter));
     # MVC object store
     MVCStore::store('mvc', $this->mvc);
     // Some commands (i.e. doctrine:query:dql) dump things out instead of returning a value
     ob_start();
     $this->application->setAutoExit(false);
     $errorCode = $this->application->run($input, $output);
     // So, if the returned output is empty
     if (!($result = $output->getBuffer())) {
         $result = ob_get_contents();
         // We replace it by the catched output
     }
     ob_end_clean();
     return array('command' => $command, 'output' => $result, 'errorCode' => $errorCode);
 }
 public function testCommand()
 {
     $app = new Application('Propel', Propel::VERSION);
     $command = new DatabaseReverseCommand();
     $app->add($command);
     $currentDir = getcwd();
     $outputDir = __DIR__ . '/../../../../reversecommand';
     chdir(__DIR__ . '/../../../../Fixtures/bookstore');
     $input = new \Symfony\Component\Console\Input\ArrayInput(array('command' => 'database:reverse', '--database-name' => 'reverse-test', '--output-dir' => $outputDir, '--verbose' => true, '--platform' => ucfirst($this->getDriver()) . 'Platform', 'connection' => $this->getConnectionDsn('bookstore-schemas', true)));
     $output = new \Symfony\Component\Console\Output\StreamOutput(fopen("php://temp", 'r+'));
     $app->setAutoExit(false);
     $result = $app->run($input, $output);
     chdir($currentDir);
     if (0 !== $result) {
         rewind($output->getStream());
         echo stream_get_contents($output->getStream());
     }
     $this->assertEquals(0, $result, 'database:reverse tests exited successfully');
     $databaseXml = simplexml_load_file($outputDir . '/schema.xml');
     $this->assertEquals('reverse-test', $databaseXml['name']);
     $this->assertGreaterThan(20, $databaseXml->xpath("table"));
     $table = $databaseXml->xpath("table[@name='acct_access_role']");
     $this->assertCount(1, $table);
     $table = $table[0];
     $this->assertEquals('acct_access_role', $table['name']);
     $this->assertEquals('AcctAccessRole', $table['phpName']);
     $this->assertCount(2, $table->xpath('column'));
 }
Пример #10
0
 private static function initializeConsoleApplication()
 {
     $app = self::$app;
     $console = new ConsoleApplication('Booothy test console runner');
     $console->setAutoExit(false);
     require 'src/App/Ui/Silex/Console/Command/App/CreateUser.php';
     self::$console = $console;
 }
 /**
  * ConsoleApplication constructor.
  *
  * ><p>**Note:** you'll have to configure the IO channels (ex. calling {@see setupStandardIO}) before running the
  * application.
  *
  * @param ConsoleIO         $io
  * @param ConsoleSettings   $settings
  * @param SymfonyConsole    $console
  * @param InjectorInterface $injector
  */
 function __construct(ConsoleIO $io, ConsoleSettings $settings, SymfonyConsole $console, InjectorInterface $injector)
 {
     $this->io = $io;
     $this->console = $console;
     $this->injector = $injector;
     $this->settings = $settings;
     $console->setAutoExit(false);
     $io->terminalSize($console->getTerminalDimensions());
 }
 public function runTest()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->add(new GreetCommand());
     $application->add(new AllCommand());
     $this->testCommand();
     $application->run();
 }
 /**
  * Runs console with the given helperset.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet  $helperSet
  * @param \Symfony\Component\Console\Command\Command[] $commands
  *
  * @return void
  */
 public static function run(HelperSet $helperSet, $commands = array(), OutputInterface $output = null)
 {
     $cli = new Application('Doctrine Command Line Interface', Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     $cli->setAutoExit(false);
     $commands = array_merge(self::getDefaultCommands(), $commands);
     $cli->addCommands($commands);
     $cli->run(null, $output);
 }
 public function runTest()
 {
     $dispatcher = $this->dispatcher = new EventDispatcher();
     $application = new Application();
     $application->setAutoExit(false);
     $application->setDispatcher($dispatcher);
     $this->testOne();
     $this->testTwo();
     $application->run();
 }
 /**
  * Launches a command.
  * If '--process-isolation' parameter is specified the command will be launched as a separate process.
  * In this case you can parameter '--process-timeout' to set the process timeout
  * in seconds. Default timeout is 60 seconds.
  * If '--ignore-errors' parameter is specified any errors are ignored;
  * otherwise, an exception is raises if an error happened.
  *
  * @param string $command
  * @param array  $params
  * @return CommandExecutor
  * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
  */
 public function runCommand($command, $params = array())
 {
     $params = array_merge(array('command' => $command, '--no-debug' => true), $params);
     if ($this->env && $this->env !== 'dev') {
         $params['--env'] = $this->env;
     }
     $ignoreErrors = false;
     if (array_key_exists('--ignore-errors', $params)) {
         $ignoreErrors = true;
         unset($params['--ignore-errors']);
     }
     if (array_key_exists('--process-isolation', $params)) {
         unset($params['--process-isolation']);
         $phpFinder = new PhpExecutableFinder();
         $php = $phpFinder->find();
         $pb = new ProcessBuilder();
         $pb->add($php)->add($_SERVER['argv'][0]);
         if (array_key_exists('--process-timeout', $params)) {
             $pb->setTimeout($params['--process-timeout']);
             unset($params['--process-timeout']);
         }
         foreach ($params as $param => $val) {
             if ($param && '-' === $param[0]) {
                 if ($val === true) {
                     $pb->add($param);
                 } elseif (is_array($val)) {
                     foreach ($val as $value) {
                         $pb->add($param . '=' . $value);
                     }
                 } else {
                     $pb->add($param . '=' . $val);
                 }
             } else {
                 $pb->add($val);
             }
         }
         $process = $pb->inheritEnvironmentVariables(true)->getProcess();
         $output = $this->output;
         $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         $ret = $process->getExitCode();
     } else {
         $this->application->setAutoExit(false);
         $ret = $this->application->run(new ArrayInput($params), $this->output);
     }
     if (0 !== $ret) {
         if ($ignoreErrors) {
             $this->output->writeln(sprintf('<error>The command terminated with an error code: %u.</error>', $ret));
         } else {
             throw new \RuntimeException(sprintf('The command terminated with an error status: %u.', $ret));
         }
     }
     return $this;
 }
Пример #16
0
 /**
  * Setup fixture. Needed here because we want to have a realistic code coverage value.
  */
 protected function setUp()
 {
     $dsn = $this->getFixturesConnectionDsn();
     $options = ['command' => 'test:prepare', '--vendor' => $this->getDriver(), '--dsn' => $dsn, '--verbose' => true];
     if (!static::$withDatabaseSchema) {
         $options['--exclude-database'] = true;
     }
     $mode = static::$withDatabaseSchema ? 'fixtures-database' : 'fixtures-only';
     $builtMode = $this->getLastBuildMode();
     if ($dsn === $this->getBuiltDsn()) {
         // we have at least the fixtures built
         // when we need a database update ($withDatabaseSchema == true) then we need to check
         // if the last build was a test:prepare with database or not. When yes then skip.
         $skip = true;
         if (static::$withDatabaseSchema && 'fixtures-database' !== $builtMode) {
             //we need new test:prepare call with --exclude-schema disabled
             $skip = false;
         }
         if ($skip) {
             $this->readAllRuntimeConfigs();
             //skip, as we've already created all fixtures for current database connection.
             return;
         }
     }
     $finder = new Finder();
     $finder->files()->name('*.php')->in(__DIR__ . '/../../../src/Propel/Generator/Command')->depth(0);
     $app = new Application('Propel', Propel::VERSION);
     foreach ($finder as $file) {
         $ns = '\\Propel\\Generator\\Command';
         $r = new \ReflectionClass($ns . '\\' . $file->getBasename('.php'));
         if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
             $app->add($r->newInstance());
         }
     }
     if (0 !== strpos($dsn, 'sqlite:')) {
         $options['--user'] = getenv('DB_USER') ?: 'root';
     }
     if (false !== getenv('DB_PW')) {
         $options['--password'] = getenv('DB_PW');
     }
     $input = new \Symfony\Component\Console\Input\ArrayInput($options);
     $output = new \Symfony\Component\Console\Output\BufferedOutput();
     $app->setAutoExit(false);
     if (0 !== $app->run($input, $output)) {
         echo $output->fetch();
         $this->fail('Can not initialize fixtures.');
         return false;
     }
     $builtInfo = __DIR__ . '/../../Fixtures/fixtures_built';
     file_put_contents($builtInfo, "{$dsn}\n{$mode}\nFixtures has been created. Delete this file to let the test suite regenerate all fixtures.");
     static::$lastBuildDsn = $dsn;
     static::$lastBuildMode = $mode;
     static::$lastReadConfigs = '';
     $this->readAllRuntimeConfigs();
 }
 /**
  * @param ContainerInterface $container
  * @param Application        $application
  *
  * @return \Symfony\Component\Console\Tester\CommandTester
  */
 private function createCommandTester(ContainerInterface $container, Application $application = null)
 {
     if (null === $application) {
         $application = new Application();
     }
     $application->setAutoExit(false);
     $command = new CopyTinyMCEFilesCommand();
     $command->setContainer($container);
     $application->add($command);
     return new CommandTester($application->find('asf:tinymce:copy'));
 }
 function assertRunCommandViaApplicationEquals($command, $input, $expectedOutput, $expectedStatusCode = 0)
 {
     $output = new BufferedOutput();
     $application = new Application('TestApplication', '0.0.0');
     $application->setAutoExit(false);
     $application->add($command);
     $statusCode = $application->run($input, $output);
     $commandOutput = trim($output->fetch());
     $this->assertEquals($expectedOutput, $commandOutput);
     $this->assertEquals($expectedStatusCode, $statusCode);
 }
 /**
  * @param ContainerInterface $container
  * @param Application        $application
  *
  * @return \Symfony\Component\Console\Tester\CommandTester
  */
 private function createCommandTester(ContainerInterface $container, Application $application = null)
 {
     if (null === $application) {
         $application = new Application();
     }
     $application->setAutoExit(false);
     $command = new InstallFontsCommand();
     $command->setContainer($container);
     $application->add($command);
     return new CommandTester($application->find('asf:twbs:fonts:install'));
 }
 private function createCommandTester(ContainerInterface $container, Application $application = null)
 {
     if (null === $application) {
         $application = new Application();
     }
     $application->setAutoExit(false);
     $command = new ChangePasswordCommand();
     $command->setContainer($container);
     $application->add($command);
     return new CommandTester($application->find('fos:user:change-password'));
 }
Пример #21
0
 /**
  * {@inheritDoc}
  * @return Application
  */
 public function createService(ServiceLocatorInterface $sl)
 {
     $cli = new Application();
     $cli->setName('DoctrineModule Command Line Interface');
     $cli->setVersion(Version::VERSION);
     $cli->setHelperSet(new HelperSet());
     $cli->setCatchExceptions(true);
     $cli->setAutoExit(false);
     // Load commands using event
     $this->getEventManager($sl)->trigger('loadCli.post', $cli, array('ServiceManager' => $sl));
     return $cli;
 }
Пример #22
0
 /**
  * {@inheritDoc}
  * @return Application
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $cli = new Application();
     $cli->setName('DoctrineModule Command Line Interface');
     $cli->setVersion(Version::VERSION);
     $cli->setHelperSet(new HelperSet());
     $cli->setCatchExceptions(true);
     $cli->setAutoExit(false);
     // Load commands using event
     $this->getEventManager($container)->trigger('loadCli.post', $cli, array('ServiceManager' => $container));
     return $cli;
 }
 /**
  * @expectedException Yosymfony\Spress\Plugin\Environment\CommandNotFoundException
  * @expectedExceptionMessage Command "foo" not found.
  */
 public function testRunCommandNotFound()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $command = new Command('acme');
     $command->setCode(function ($input, $output) {
         $output->writeln('acme');
     });
     $application->add($command);
     $environment = new SymfonyCommandEnvironment($command, new ConsoleOutput());
     $environment->runCommand('foo', []);
 }
Пример #24
0
 function it_should_use_passed_options_rather_than_default_params(InputInterface $input, Application $application)
 {
     $input->hasOption('no-interaction')->willReturn(true);
     $input->getOption('no-interaction')->willReturn(false);
     $input->hasOption('env')->willReturn(true);
     $input->getOption('env')->willReturn('dev');
     $input->hasOption('verbose')->willReturn(true);
     $input->getOption('verbose')->willReturn(true);
     $arrayInput = new ArrayInput(array('command' => 'command', '--no-debug' => true, '--env' => 'dev', '--no-interaction' => true, '--verbose' => true));
     $application->setAutoExit(false)->shouldBeCalled();
     $application->run($arrayInput, new NullOutput())->willReturn(0);
     $this->runCommand('command', array('--no-interaction' => true));
 }
Пример #25
0
 public function testCommandFromApplication()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $command = new Command('foo');
     $command->setCode(function ($input, $output) {
         $output->writeln('foo');
     });
     $application->add($command);
     $tester = new CommandTester($application->find('foo'));
     // check that there is no need to pass the command name here
     $this->assertEquals(0, $tester->execute(array()));
 }
 private function createCommandTester(ContainerInterface $container, $extraCommands = [])
 {
     $application = new Application();
     $application->setAutoExit(false);
     $command = new CronScanCommand();
     $command->setContainer($container);
     foreach ($extraCommands as $extraCommand) {
         $extraCommand->setContainer($container);
         $application->add($extraCommand);
     }
     $application->add($command);
     return new CommandTester($application->find('cron:scan'));
 }
Пример #27
0
 /**
  * If $catchException, application will render Exception internally.
  * If $autoExit, application will exit in this function.
  */
 public function execute(array $config, $catchException = true, $autoExit = true)
 {
     $application = new Application();
     $application->setCatchExceptions($catchException);
     $application->setAutoExit($autoExit);
     foreach ($config as $command) {
         if (!class_exists($command)) {
             print_r(Command::red("Command Not Found: [{$command}]\n"));
         } else {
             $application->add(new $command());
         }
     }
     $application->run();
 }
Пример #28
0
 /**
  * Loads doctrine fixtures for test isolation
  * @throws \Exception
  */
 public static function setUpBeforeClass()
 {
     $kernel = new \AppKernel('test', false);
     $kernel->boot();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $options['-e'] = 'test';
     $options['-q'] = null;
     $options['-n'] = true;
     $options['--purge-with-truncate'] = null;
     $options['--fixtures'] = __DIR__ . '/../../DataFixtures/ORM/';
     $input = new ArrayInput(array_merge($options, array('command' => 'doctrine:fixtures:load')));
     $application->run($input);
 }
Пример #29
0
 /**
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return Application
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get(ConfigHelper::class);
     $commandManager = $serviceLocator->get('CommandManager');
     $commands = array_values($commandManager->getCanonicalNames());
     $application = new Application($config->get('application.name'), $config->get('application.version'));
     foreach ($commands as $command) {
         $application->add($commandManager->get($command));
     }
     $application->setHelperSet(new HelperSet());
     $application->setCatchExceptions(true);
     $application->setAutoExit(false);
     $this->getEventManager($serviceLocator)->trigger('loadCli.post', $application, array('ServiceManager' => $serviceLocator));
     return $application;
 }
 /**
  * Execute the TgaLetsEncrypt command with specific parameters.
  *
  * @param array $parameters
  * @return CommandTester
  */
 public function execute($parameters = [])
 {
     $parameters = array_merge(['letsencrypt' => 'php ' . __DIR__ . '/../Fixtures/mockscript-ok.php', 'recovery_email' => '*****@*****.**', 'domains' => ['example.org'], 'logs_directory' => __DIR__ . '/../Fixtures/tmp', 'monitoring.email.enabled' => false, 'monitoring.email.to' => []], $parameters);
     $container = new Container();
     foreach ($parameters as $name => $value) {
         $container->setParameter('tga_lets_encrypt.' . $name, $value);
     }
     $command = new TgaLetsencryptCommand();
     $command->setContainer($container);
     $application = new Application();
     $application->add($command);
     $application->setAutoExit(false);
     $command = $application->find('tga:letsencrypt');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName()]);
     return $commandTester;
 }